magqq
magqq

Reputation: 1023

Count the number of times a word appears in a file

What is an easy way to count the number of times a word appears in a file?

Upvotes: 68

Views: 85076

Answers (3)

venkatesh
venkatesh

Reputation: 52

fgrep "word to be counted" filename|wc -w

Upvotes: -1

mohit6up
mohit6up

Reputation: 4348

This will also count multiple occurrences of the word in a single line:

grep -o 'word' filename | wc -l

Upvotes: 151

Alexander Torstling
Alexander Torstling

Reputation: 18898

cat filename | tr ' ' '\n' | grep 'word' | wc -l

Upvotes: 3

Related Questions