How do I find files that do not contain a given string pattern?

后端 未结 16 1319
半阙折子戏
半阙折子戏 2020-11-28 17:42

How do I find out the files in the current directory which do not contain the word foo (using grep)?

16条回答
  •  心在旅途
    2020-11-28 17:48

    My grep does not have any -L option. I do find workaround to achieve this.

    The ideas are :

    1. to dump all the file name containing the deserved string to a txt1.txt.
    2. dump all the file name in the directory to a txt2.txt.
    3. make the difference between the 2 dump file with diff command.

      grep 'foo' *.log | cut -c1-14 | uniq > txt1.txt
      grep * *.log | cut -c1-14 | uniq > txt2.txt
      diff txt1.txt txt2.txt | grep ">"
      

提交回复
热议问题