--count-matches to count all occurrences, not just lines like --count
To count the total number of matches, rather than the number of matching lines, the recommended solution is to pipe ack -o to wc -l. There’s nothing wrong with this solution as far as I can tell, but I noticed that ripgrep added --count-matches one year ago. Should ack have the same? Should there be a short alias?
See also: #15, https://github.com/beyondgrep/ack2/issues/563, https://github.com/beyondgrep/ack2/issues/623, https://github.com/BurntSushi/ripgrep/pull/814.
Should ack have the same?
Would you use it? What would the use case be?
Yes, I would definitely use it often if it had a convenient one-letter alias, similar to -c. I do use -c all the time, but realize it's not exactly what I want if multiple matches can occur on the same line and I want to count all matches. In that case, it adds much time and keystrokes to do a double-take on the unexpected results, then copy and append to the previous command. I often work with various types of unwrapped text files containing prose, in which each paragraph takes up one long line. The prose is often loosely structured, and I need to check at arbitrary times if each file has the expected number of key phrases and words. I like to use ack in rapid prototyping because it is more convenient (groups results by file, ignores non-text files, has useful short flags) than grep and other relatives. (I’d also make an uneducated guess that this wouldn’t be a hard-to-implement feature.)
Why not use the combination of options -c and -o, i.e. -co to count all occurrences? It is logical, though GNU/BSD grep don't offer this combo. The ugrep implementation does support this, see Counting the number of matches with -c and -co.