Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grep : get all file that doesn't have a line that matches [closed]

Tags:

I have a lots of files with multiple lines, and in most case, one of the lines contain a certain pattern. I would like to list every file that does not have a line with this pattern.

like image 897
claf Avatar asked May 19 '09 06:05

claf


2 Answers

Use the "-L" option in order to have file WITHOUT the pattern. Per the man page:

-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.

like image 141
claf Avatar answered Sep 25 '22 01:09

claf


Grep returns 0/1 to indicate if there was a match, so you can do something like this:

for f in *.txt; do     if ! grep -q "some expression" $f; then         echo $f     fi done 

EDIT: You can also use the -L option:

grep -L "some expression" *

like image 37
JesperE Avatar answered Sep 23 '22 01:09

JesperE