Mailing List Archive


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

Re: [tlug] GREP basics



On Thu, 2003-01-30 at 23:45, Charles Muller wrote:
> 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.
> 
> But if I do:
> 
> [chuck@example.com ddbxml]$ grep -c "<hdwd>" * 
> 
> I get a list of the 82 files, with the number of hits in each listed next to
> them, but not the grand total.
> 
> If I do:
> 
> [chuck@example.com ddbxml]$ grep "<hdwd>" * 
> 
> Then I get a list of each of the lines containing this occurrence, but again, no
> total number at the end.
> 
> 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?

If your "<hdwd>" is a "word" (I mean always being separated by known
characters, such as space, tabs, or why not ":", there are some easy
solutions. The idea would be to 'cut' lines by words, then a simple
grep would do the job.

If not, it is more difficult. But, fur CPU savings, I would suggest to
"cut" lines on the first (or last) char of your string, then "grepping"
with '^' or '$' depending on your choice.

br.

-- 
GPG Key: 653514E5 (http://www.raoult.com/gpg)
--
Computers are like air-conditions. They don't properly work, if you open
Windows.

Attachment: signature.asc
Description: This is a digitally signed message part


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links