Search code examples
grep

Grep command for including a set of letter and excluding the others


I need all files with lines including the word "confidential" But not having this sentence "waste paper is confidential and need to be disposed"

grep confidential 100*.cvt 

gives me lines that contain word "confidential"

How do I remove programs with this sentence "waste paper is confidential and need to be disposed"

grep confidential 100*.cvt | grep -v waste paper is confidential and need to be disposed 100*.cvt

Solution

  • Use grep -l to get just the filenames from the first grep. Then use that as the filename arguments to the second grep.

    You also need to quote the pattern if it contains whitespace.

    grep -l confidential 100*.cvt | xargs grep -l -v 'waste paper is confidential and need to be disposed'