count occurrences of string in txt file command line mac code example Example: find number of occurances of a string in a file shell $ grep -o -i needs inspire.txt | wc -l