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.
grepthat has the non-standard-ooption? Are you interested in substrings of words, likeworldin the stringotherworldly? If not, what constitute a word? IsUnix-likeone word, or the two wordsUnixandlikeand doesyou'dmatch the wordyou?grepping 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?