Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to find the word count of a specific word in a collection of documents, in Linux.

I have tried with grep and ack-grep in combination with wc but I can't seem to come up with a valid combination of pipes :)

share|improve this question
up vote 6 down vote accepted

Try the following:

grep -o "string" filename | wc -w

If you want all files in a directory, run the following script from that directory:

for file in *
    do let count=$count+`grep -o "wordyouaretryingtofind" $file | wc -w`
done
echo occurence $count times
share|improve this answer
    
Cheers; I was missing that -o argument – Andreas Grech Jun 16 '10 at 15:25
    
Added something you might like – BloodPhilia Jun 16 '10 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .