Strange results from using grep

Alex Dyas alex.dyas at interoute.com
Tue Oct 3 08:25:46 BST 2006


Stephen Allen wrote:
> I'm trying to check if any string from a pattern file, matches or
> part-matches a fixed string, using the command 'echo <string> | grep -f
> <pattern_file>'
> 
> When tested on Fedora Core 3, the results are as expected:
> 
>       $ cat pattern_file
>       admin
>       postmaster
>       daemon
> 
>       $ echo 'Mailer-Daemon <postmaster at somedomain.tld>' | grep -f
> pattern_file
>       Mailer-Daemon <postmaster at somedomain.tld>
> 
>       $ echo 'None of this is in the pattern file' | grep -f pattern_file
> 
> As you can see, when nothing matches, nothing is echoed back from the
> command.  However, when tested on FreeBSD-6.1, it fails to find a match
> in the same way and stubbornly just echoes out the string I'm looking
> for.  This is the same with or without the trailing '-' to force grep to
> read from stdin.
> 
>       $ echo 'None of this is in the pattern file' | grep -f pattern_file
>       None of this is in the pattern file
> 
>       $ echo 'This is always echoed out' | grep -f pattern_file
>       This is always echoed out
> 
> Any ideas?

On my 6.1-RELEASE it works as documented:

shrew% uname -sr
FreeBSD 6.1-RELEASE
shrew% 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.

shrew% cat pattern_file
admin
postmaster
daemon
shrew% echo 'None of this is in the pattern file' | grep -f pattern_file
shrew% echo 'Mailer-Daemon <postmaster at somedomain.tld>' | grep -f 
pattern_file
Mailer-Daemon <postmaster at somedomain.tld>

Alex..
-- 
-= Alex Dyas - UNIX - Interoute - Geneva =-




More information about the Ukfreebsd mailing list