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.

what is the Unix and Linux command to list the number of occurrences of a word in a file?

I did not get the results I was looking for using grep -c 'word' <file name>

I would like to display:

word
word
word

and the number 3

share|improve this question

migrated from stackoverflow.com Jan 7 '13 at 6:20

This question came from our site for professional and enthusiast programmers.

    
look for "wc -w" –  Icarus3 Jan 7 '13 at 1:23
    
what is the complete command? grep -c 'word' <file> | wc -w ? –  Yoyo Me Jan 7 '13 at 1:25
    
grep -ri "word" <file> | wc -w –  Icarus3 Jan 7 '13 at 1:27
    
Thank you ! ! ! ! –  Yoyo Me Jan 7 '13 at 1:37
    
grep -ow 'word' <file> | tee >(wc -w) use this in case you want list of word to be printed too –  Icarus3 Jan 7 '13 at 1:51

1 Answer 1

Assuming word shows up at most once per line (or you don't care), you can do it with a simple pipe:

grep word file | wc -l

share|improve this answer

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.