Search This Blog

2013-08-30

Counting Matches in Grep

Grep traditionally will only match lines so if you run a wc -l it will count total matching lines rather than total matching patterns.

You can use
grep -o "pattern"

Which will separate each match onto its own line, this allows you to easily wc -l to count all matches.

No comments:

Post a Comment