How can I exclude one word with grep?

后端 未结 9 2432
孤独总比滥情好
孤独总比滥情好 2020-12-12 09:01

I need something like:

grep ^\"unwanted_word\"XXXXXXXX
相关标签:
9条回答
  • 2020-12-12 09:34

    I've a directory with a bunch of files. I want to find all the files that DO NOT contain the string "speedup" so I successfully used the following command:

    grep -iL speedup *
    
    0 讨论(0)
  • 2020-12-12 09:35

    Invert match using grep -v:

    grep -v "unwanted word" file pattern
    
    0 讨论(0)
  • 2020-12-12 09:39

    You can do it using -v (for --invert-match) option of grep as:

    grep -v "unwanted_word" file | grep XXXXXXXX
    

    grep -v "unwanted_word" file will filter the lines that have the unwanted_word and grep XXXXXXXX will list only lines with pattern XXXXXXXX.

    EDIT:

    From your comment it looks like you want to list all lines without the unwanted_word. In that case all you need is:

    grep -v 'unwanted_word' file
    
    0 讨论(0)
提交回复
热议问题