1

Say I have 1000 files in multiple recursive folders and say the string 'testing' is in 600 files and total number of mention of 'testing' within those 600 files is 750 times. Then - I need something like "750 matches across 600 files"

I got close as -

grep -Rcl 'string' .

Which gives me name of every file but I just want the numbers.

and

grep -roh 'string' . | wc -w

Which gives me just the number of occurrences

Can you please let me have the whole command?

Thank you

4
  • 2
    Could you clarify what number? I guess you mean number of occurrences per file, with the filename. Please edit your question and add an example of the desired output. Commented Oct 31, 2022 at 15:14
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Oct 31, 2022 at 16:30
  • I have edited the question and I hope maybe you wanted this clarifications. Thank you for your reply. @mashuptwice
    – Rajib Paul
    Commented Oct 31, 2022 at 17:07
  • I got the number of calls/occurrences with grep -roh 'string' . | wc -w and how can I get the number of files, not the file names just the number. Thank you. @Community
    – Rajib Paul
    Commented Oct 31, 2022 at 17:09

1 Answer 1

1

You won't be able to do that with a single command, but you can combine multiple:

echo "$(grep -R asdf | wc -l) matches in $(grep -Rl asdf | wc -l) files"

outputs:

40 matches in 20 files

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .