Show total count of matches

22 views Asked by At

I run rg "\bres\b" --stats on my code and it shows be such stats:

665 matches
534 matched lines
149 files contained matches
3603 files searched
33871 bytes printed
9805953 bytes searched
0.445034 seconds spent searching
0.083803 seconds

I only want to know that there are 665 matches, and ideally run command like this with the output of:

$ rg "\bres\b" --total-matches
665

Is there a way to do it? I am not interested in grepping this stat from the output of command with --stats.

1

There are 1 answers

0
Max Smirnov On

I found that this command shows exact same number as in --stats:

rg {regex} --count-matches --no-filename | awk '{s+=$1} END {print s}'