Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 26 Mar 2003 14:47:33 -0800
From:      Steve Willoughby <steve@ichips.intel.com>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: perl help 
Message-ID:  <200303262247.h2QMlX1c024334@plxs0062.pdx.intel.com>
In-Reply-To: Message from Dan Nelson <dnelson@allantgroup.com>  <20030326222940.GB38860@dan.emsphone.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> In the last episode (Mar 27), Giorgos Keramidas said:
> > On 2003-03-26 14:18, Kenzo <kenzo_chin@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@ichips.intel.com>  | of floating ice."           --Strata R. Chalup




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200303262247.h2QMlX1c024334>