How can I print a filename if the file doesn't contain a string?
grep -vl 'string' file
always prints file
, I guess because there is at least one line per file that isn't string
.
$ ls
one two three four five
$ grep -l 'odd' *
one
three
five
$ grep -lv 'odd' *
one
two
three
four
five
But I want it to print the inverse of the first option
two
four
According to grep
documentation:
-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 of each file stops on the first match.
So, you need to use
grep -L 'odd' *
four
two