Best way to get a total number of all matches from all files #2722
-
It looks like ripgrep can only show total number of matches per file or via the Can I do better than this? rg -q --stats search | head -n 2 | awk '{print$1}'
rg -q --stats search | head -n 2 | cut -d\ -f1 The other (less performant) options are: rg -o search | wc -l
rg -q --stats --json search | jq '.data.stats.matches' |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
Nope. You could do In general ripgrep doesn't really have any aggregate mode for an entire search. It only has aggregate mode for individual files. |
Beta Was this translation helpful? Give feedback.
-
You could use the json output and jq; it seems less likely to break if the stats output ever changes: rg -q --stats --json search | jq '.data.stats.matches' |
Beta Was this translation helpful? Give feedback.
Nope. You could do
rg -o search | wc -l
, but your method is almost certainly faster, and perhaps substantially so in some cases.In general ripgrep doesn't really have any aggregate mode for an entire search. It only has aggregate mode for individual files.