0

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

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

1 Answer 1

0

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

You must log in to answer this question.

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