Strange results from using grep

N.J. Mann njm at njm.f2s.com
Tue Oct 3 08:25:48 BST 2006


On Tue 03 Oct 07:55, 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?

I just tried this on my week old FreeBSD 6.2-PRERELEASE and it works as
I would expect it to:

  > 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

  > echo 'This is always echoed out' | grep -f pattern_file

So, something is different between your setup and mine.  I had a quick
look on cvsweb.freebsd.org and it looks like we should be using the same
version of grep, but...

Are you sure the grep that is being executed is the system one?  On my
system I get:

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

Sorry I cannot be of more help, but I suspect there is something wrong
at your end. :-(


Cheers,
       Nick.
-- 
"With sufficient thrust, pigs fly just fine.  However, this is not
necessarily a good idea.  It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly overhead."
 -- RFC 1925




More information about the Ukfreebsd mailing list