Count Occurrences of a String in a File

This page answers questions like these:


Related Links:
Count Occurrences of a Hexadecimal Sequence in a File



Count Number of Lines in a File Containing a String:

grep -c STRING FILE ...

Count Number of Occurrences of a String in a File:

grep -o STRING FILE ... | wc -l grep STRING FILE ... | sed 's/STRING/&\n/g' | grep -c STRING

Count Number of Occurrences of a String in a Binary File:

strings -a -n 1 FILE ... | sed 's/STRING/&\n/g' | grep -c STRING


Related Links:
Count Occurrences of a Hexadecimal Sequence in a File

Home  >  Linux / Unix  >  Count Occurrences of a String in a File


Tags: count, string, pattern, file, text file, binary file, linux, unix, solaris, bsd, aix

Copyright © HelpDoco.com
file-count-string.txt
Linux-Unix/count-occurrences-of-string-in-file.htm
3