On 31/10/2012 16:40, LuKreme wrote:
I want to grep for words in a file that contain 'a' 'b' and 'c' in any order. I
also want to find words that contain two c's, even if not together (so access
and chance).
I might even want words with two c's AND a and b, again in any order.
I feel like I am forgetting something basic.
As for most of these things, as text filter is the best solution. This:
#! /usr/bin/perl
use strict;
while (<>) {
print;
my @hits;
my @words = split /\b/, $_;
for (@words) {
push @hits, $_ if /a/i and /b/i and /c/i or /c.*c/i;
}
printf "• Found: %s\n", join ", ", @hits if @hits;
undef @hits;
}
will turn
The accountant sat in the back of the
cab wearing a black cocked hat
into
The accountant sat in the back of the
• Found: accountant, back
cab wearing a black cocked hat
• Found: cab, black, cocked
JD
--
--
You received this message because you are subscribed to the
"BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem,
please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>