ack foo *
returns a listing of lines:
bar.txt
28: this is foo stuff
dump.txt
12: results of foo
gobs.txt
1137: more lines with foo
and
ack -c -l
returns
3
My question is, how can I show both? I'd like the list of lines as in the first example and a count of the number of lines that matched as in the second example.
You can use
ack -hc
(-h
being shorthand for --no-filename
) to get a total count.
According to the ack documentation/man page:
-c, --count
Suppress normal output; instead print a count of matching lines for each input file. If
-l
is in effect, it will only show the number of lines for each file that has lines matching. Without-l
, some line counts may be zeroes.If combined with
-h
(--no-filename
)ack
outputs only one total count.
Here's what worked for me (expanding on @Jordan's answer) --
ack 'pattern' && ack -hc 'pattern'
or, better (IMO):
ack 'pattern'; ack -hc 'pattern'
As far as I understand, using &&
, the second command depends on the first one returning to run; using ;
instead will just run them both, one after the other, regardless. In this case, I think the ;
is more appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With