Task:
1) find a string 'decor' inside files in a directory
2) get # of occurrence for decor for each file that has it
The first part of the problem is partially solved with find . -type f | grep -i decor *
But this doesn't seem grep
for all files that are found from find
but rather what's on top of current directory.
Do I have to use something other than *
for grep
to grep for files found from find?
what needs to be piped to so that it will display with a file name and the number of occurrences for decor for each file?
Answer
You can do:
find . -type f -exec grep -icH decor {} \; | grep -v :0\$
This will get the filename and count of each match and remove files with a count of 0 using the piped egrep
No comments:
Post a Comment