Skip to main content
1 of 3
frabjous
  • 9.2k
  • 1
  • 38
  • 34

With GNU grep:

grep -w -o -i "orange" filename | wc -l

Here the -w makes it only match whole words; the -o makes it split each occurrence of a match on the same line into its own line and suppresses other output, and the -i makes it case-insensitive, so it'll match Orange as well. (If you don't want that, take out the -i.)

This is then passed to wc which counts the words. Since each is on its own line you could use wc -l or wc -w and the results will be the same.

frabjous
  • 9.2k
  • 1
  • 38
  • 34