Strange results from using grep

Stephen Allen freebsduk at rowyerboat.com
Tue Oct 3 07:55:45 BST 2006


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?

Thanks,
Steve :)




More information about the Ukfreebsd mailing list