Count occurrences of a string in a file
11 March 2022 (Updated 11 March 2022)
cat myfile.txt | grep 'foo' -o | wc -l
This will print the number of times the string foo
appears in myfile.txt
. This is useful when you need to count string occurrences as part of some script.
Tagged:
Unix
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment