Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.