5

This question already has an answer here:

I have a set of files that contain some information.
I am interested in the subset of files that do not contain a specific pattern at all.
E.g.

cat file.txt  
foo  
bar  
trivial information
some customer data   

let’s say that I am interested in files that do not have the line ‘trivial information’.
How would I do that?
If I do:

grep -v ‘trivial information’   

it will not work because the rest of the lines in the file are match to this inverted search so the file.txt will end up in the result.
So how do I do an invert match on the whole file and not line by line?

marked as duplicate by don_crissti, terdon Apr 14 '17 at 13:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

14

You are looking for the -L flag:

grep -L 'trivial information' *

From man grep:

-L, --files-without-match

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

  • 2
    I wish I remembered that switch in the future, I've done for f in ... grep $p $f >/dev/null || echo $f a couple of times... – ilkkachu Apr 14 '17 at 13:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.