Discussion:
grep: Listing files without lines matching a pattern
(too old to reply)
Michael Grünewald
2014-11-12 07:41:12 UTC
Permalink
In my version of GNU grep (see below) using both *-l* and *-v* (in that
order) leads to *-v* being silently ignored.

My intent by using *-l* and *-v* was to achieve the effect of *-L*,
listing files without lines matching a pattern. Seeing the option *-v*
being silently ignored in this context is a surprising effect, which
should be documented and maybe could lead *grep* to fail with a “Usage”
error.

Best regards,
Michael Grünewald


grep --version
grep (GNU grep) 2.5.1-FreeBSD

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Norihiro Tanaka
2014-11-12 14:17:03 UTC
Permalink
On Wed, 12 Nov 2014 08:41:12 +0100
Post by Michael Grünewald
My intent by using *-l* and *-v* was to achieve the effect of *-L*,
listing files without lines matching a pattern.
No. -L is different from -lv, and -Lv is also different from -l.

$ printf 'a\n' > in_a
$ printf 'b\n' > in_b
$ printf 'a\na\n' > in_aa
$ printf 'a\nb\n' > in_ab

$ grep -l a in_a in_b in_aa in_ab
in_a
in_aa
in_ab

Files which a line matches `a'.

$ grep -lv a in_a in_b in_aa in_ab
in_b
in_ab

Files which a line does not match `a'.

$ grep -vl a in_a in_b
in_b
in_ab

Same above.

$ grep -L a in_a in_b in_aa in_ab
in_b

Files which all lines do not match `a'.

$ grep -Lv a in_a in_b in_aa in_ab
in_a
in_aa

Files which all lines match `a'.

$ env LC_ALL=C grep --version | head -1
grep (GNU grep) 2.20

Loading...