Tuesday, February 17, 2009

Counting the occurance of a string in a file

The following counts the number of lines the occurrence of the word "test" occurs in a file:
grep -c " test " filename

Counting all occurrences:
grep -o " test " filename | wc -w

No comments:

Post a Comment