0

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
theonlygusti
  • 11,032
  • 11
  • 64
  • 119

1 Answers1

1

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
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563