Use grep to quickly count occurrences of a string in a file

Sep 02, 2020
cat myfile.txt | grep 'foo' -o | wc -l

This will print the number of times the string foo appears in myfile.txt.