[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: grep bug
From: |
Alain Magloire |
Subject: |
Re: grep bug |
Date: |
Sun, 29 Jul 2001 15:19:05 -0400 (EDT) |
>
> First, the version.
>
> $ grep --version
> grep (GNU grep) 2.4.2
> $
>
> Initially, I have two files, strings and list.
>
> $ cat strings
> $ cat list
> a
> b
> c
> d
> $
>
> Now, I want to do some simple whole-line string matching.
>
> $ grep -xf strings list
> a
> b
> c
> d
> $
>
> The results of the above command are _very_ wrong. An empty strings file
> should match nothing. Without x?
>
> $ grep -f strings list
> $
>
> Nothing matches, as expected.
>
> Next, apply -v to reverse the results. The expected result is that list will
> just be cat'ed, since nothing matches an empty strings file.
>
> $ grep -xvf strings list
> $
>
> But, there's no output!
>
> Things work properly with a nonempty strings file:
>
> $ echo a > strings
> $ grep -xf strings list
> a
> $ grep -xvf strings list
> b
> c
> d
>
> So, the bug is that when -f refers to an empty file, the -x option acts like
> a -v. Of course, things work correctly with a pattern of "" passed on the
> commandline, but GNU grep gets confused when the same is passed via -f.
>
> This is an irritating bug, and it has cost me a lot of time piecing some data
> files back together again from scrollback logs after testing scripts that ran
> into this bug.
Are you sure that the file was empty? i.e. it did not contain a bare '\n'.
Some
editors when saving leaves a NewLine.
I'm testing with the grep version from the repository, but this should apply
to grep version 2.4.2 also:
# grep -xf /dev/null /etc/passwd
# grep -f /dev/null /etc/passwd
# cat /etc/motd
adm:x:3:4:adm:/var/adm:
lp:x:4:7:lp:/var/spool/lpd:
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:
news:x:9:13:news:/var/spool/news:
....
# grep --version
grep (GNU grep) 2.5f
Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
...
--
au revoir, alain
----
Aussi haut que l'on soit assis, on est toujours assis que sur son cul !!!
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: grep bug,
Alain Magloire <=