Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] GREP basics



Quoth Charles Muller (Thu 2003-01-30 11:45:46PM +0900):
>
> I have a directory that contains 82 files. I want to get a count of the
> number of occurrences of the word "<hdwd>" in all 82 files.

[...]

> I have looked at all of the options listed in _man grep_, but I don't see
> anything for listing just the total number of hits at the end.  I would
> think that this must be a rather elementary GREP function, but I don't see
> any explanation for it. Can anyone give me a clue?

I can't tell you the grep option, but this will work:


grep -ci "Captain's Log" * | perl -e \
'$num=0;
while(<>){ my @example.com = split(/\:/); $num += $foo[1]; }
print "$num\n";'


You could accomplish the same thing with awk in a shell script.


-- 
Josh Glover <jmglov@example.com>

Associate Systems Administrator
INCOGEN, Inc.
http://www.incogen.com/

GPG keyID 0x62386967 (7479 1A7A 46E6 041D 67AE  2546 A867 DBB1 6238 6967)
gpg --keyserver pgp.mit.edu --recv-keys 62386967

Attachment: pgp00094.pgp
Description: PGP signature


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links