This is off-topic, but google didn't seem to have anything on this
topic (maybe someone here can point me in the right direction):
I want to grep a large list of files and find out which ones have a
certain string (currently available with "grep -l"). Then I want to
count how many instances that string is found in each (with "grep
-c").
I've been able to figure out how to do this in the reverse order with this:
grep -c "search-string" filename... | grep -v ":0"
This will count the instances of "search-string" in all files matching
"filename", then pipe those results to the second grep expression
which only searches for anything that does NOT include a zero-count
(the ":0" expression).
This gives the correct output. But I wanted to use the standard IO as
a list of files to grep through and give me a total count. Currently,
I only know of "-f" or "--file=filename" which will parse a file for
names of files we want to search through. IS there a way to do this
using the "-l" switch?
grep -l "search-string" filename... | grep -c "search-string" --file=stdio
(or something similar)
I know, off-topic. But if anyone knows, it'd be great to hear from you.
|