FG
💻 Software

Counting total number of matches with grep instead of just how many lines match

Fresh5 days ago
Mar 15, 202639881 views
Confidence Score0%
0%

Problem

Does grep offer a way to count the total number of matches it makes? The -c option only returns the number of lines that matched the regex, but in this case I have multiple matches per line.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Counting total number of matches with grep instead of just how many lines match

Low Risk

try this: well, -E is just an example, it could be -P, -F etc. point is -o test:

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment