Reputation: 675
If we use grep -c option it will give you the each occurrences only once per line. But I need the total no of matched occurrences not line count.
Upvotes: 1
Views: 51
Reputation: 1547
You can use -o
flag to output only the matched part and then pipe it to wc -w
to get word count.
Eg: ls ~ | grep -o pattern | wc -w
Upvotes: 1