Skip to content

Latest commit

 

History

History
13 lines (9 loc) · 490 Bytes

count-matches-in-file.md

File metadata and controls

13 lines (9 loc) · 490 Bytes

Count matches in file

Using grep, it is easy to count the occurrences of a string or regular expression in a file. Using the -o flag, it will print each individual match to its own line, which can then just be counted with the wc utility:

$ grep -o "match" ./count-matches-in-file.md | wc -l

If the file is binary, the -a flag can be used.

source