3 ms·
Fwiw I would first reach for grep -c but that has the wrong semantics here as it counts matching lines. I think rg -c is the same but IIRC it also has a --count
by dan-robertson 4y ago
Fwiw I would first reach for grep -c but that has the wrong semantics here as it counts matching lines. I think rg -c is the same but IIRC it also has a --count-matches flag which does what you want. But I don’t think that invalidates your point; I think I got lucky and happened to know how to do this already. And it may be that your program is faster anyway (or that it adapts well if you have multiple patterns)