Bob Showalter am Donnerstag, 30. März 2006 23.32:
> Chas Owens wrote:
> > If we are going to pick nits then it should be
> >
> > grep -c "<employee>" fn
>
> Note that grep -c counts matching *lines*. There is no formal
> requirement that these elements appear on separate lines.
Dave,
my first one-liner suffers from the same (also only counts lines)
> Here's a slightly more complex Perl one-liner that counts *occurences*
>
> perl -lne '$n++ for /<employee>/g; END {print $n}' somefile.xml
Bob,
thanks, I thought about the -n option, but missed the END block idea to
finally print the sum.
(And again, problems that seem to be trivial are not in many cases...)
Hans
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>