perl help
Steve Willoughby
steve at ichips.intel.com
Wed Mar 26 22:47:38 PST 2003
> In the last episode (Mar 27), Giorgos Keramidas said:
> > On 2003-03-26 14:18, Kenzo <kenzo_chin at hotmail.com> wrote:
> > You don't need Perl for that. Here's a small trick:
> > grep 'this' file | wc -l
> > grep 'that' file | wc -l
> Even better:
> grep -c 'this' file
> grep -c 'that' file
Unfortunately, that's not what he was asking for, which is to look for
the pattern "big <foo>" where all the possible <foo>s are unknown and
report on all the <foo>s that were found.
So something like:
while (<>) {
while (/big\s+(\w+)/g) {
$count{$1}++;
}
}
foreach $word (sort(keys(%count))) {
print "$word: $count{$word}\n";
}
ought to do the trick. Play with $/, etc if you want to allow big and
<foo> to be across a newline from each other.
--
Steve Willoughby | "The purpose of IT is to seamlessly and trans-
Intel DPG Eng. Computing | parently provide the other nine-tenths of the
Application Development | iceburg for people who need to work with chunks
<steve at ichips.intel.com> | of floating ice." --Strata R. Chalup
More information about the freebsd-questions
mailing list