tags:

views:

507

answers:

4

This may be a duplicate as I believe I already saw something like that but can't find it anymore so I'm asking :

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

EDIT : Just need to use the "-L" grep option. This is a duplicate, I'm sure but don't find the original back ...

+2  A: 

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" *

JesperE
no need for loop just have to use "-L" option of grep.
claferri
A: 

Use the -v option. Man page excerpt:

-v, --invert-match
    Invert the sense of matching, to select non-matching lines.  (-v is specified by POSIX.)

As always, use man

Edit: No need to use for loops, just use the wildcard char:

grep -v "some expression" *
atc
No sorry, this will give me every line that doesn't contain the match ... How did you get +3 on this!
claferri
People vote without reading and/or understanding the post, unfortunately.
JesperE
I totally misread the question it seems - I've been up since 5 AM, so forgive me!
atc
`grep -lv 'expr' *` should do the same as `grep -L 'expr' *`, so this answer is incomplete, not incorrect.
amertune
+2  A: 

The answer was just to get the "-L" option in order to have file WITHOUT the pattern ... Should have read the man more carrefully!

claferri
A: 

try "count" and filter where equals ":0":

grep -c [pattern] * | grep ":0"

(if you use TurboGREP cough, you won't have a -L switch ;))

devio
TurboGREP does seem to have -l and -v, so you could just use `grep -lv 'expr' *`.
amertune