Use grep to quickly count occurrences of a string in a file
Here’s a neat one-liner for counting the number of times a string appears in a file.
cat myfile.txt | grep 'foo' -o | wc -l
This will print the number of times the string
foo appears in
Ofcourse, I could just open a modern text editor and use its find word feature but sometimes I just want to feel smart.