Count all occurrences of a string in lots of files with grep

前端 未结 15 1595
广开言路
广开言路 2020-11-28 01:07

I have a bunch of log files. I need to find out how many times a string occurs in all files.

grep -c string *

returns

...
f         


        
15条回答
  •  被撕碎了的回忆
    2020-11-28 01:33

    You can use a simple grep to capture the number of occurrences effectively. I will use the -i option to make sure STRING/StrING/string get captured properly.

    Command line that gives the files' name:

    grep -oci string * | grep -v :0
    

    Command line that removes the file names and prints 0 if there is a file without occurrences:

    grep -ochi string *
    

提交回复
热议问题