Home > Software engineering >  How to fetch and display just the count of grep matches against each file that has the matching stri
How to fetch and display just the count of grep matches against each file that has the matching stri

Time:07-07

cat Samplescript
for OUTPUT in $(grep -lR "Sample sv15 Processor" ./*) #List files with matching string
do
    grep "Sample sv15 Processor" $OUTPUT | wc -l
done

My approach is to list files with matching strings
Then run a grep search against each file name from the list.
Finally, use wc -l via pipeline

What am I missing?

CodePudding user response:

As hinted by @root in the comments grep -cR 'stringtomatch' ./* will do the task.

  • Related