I need to search a text file for a word count. The file contains lines of sentences and I only care about the number of times a word shows up not the number of lines. How do I tell grep to search for words instead of lines?
For instance if I use, grep -c '^ab'
(words that start with ab
), it only returns the number of lines that begin with ab
, not the number of words that begin with ab
.
grep
that has the non-standard-o
option? Are you interested in substrings of words, likeworld
in the stringotherworldly
? If not, what constitute a word? IsUnix-like
one word, or the two wordsUnix
andlike
and doesyou'd
match the wordyou
?grep
ping without the^
, the beginning-of-line anchor.ab
”. Please clarify: are you looking for a word, or for all words that match a pattern? (2) If you want to look for a pattern, think about multiple occurrences. For example, if you were looking for all words containingab
, would “habitable” count as one or two?