[lug] finding text lines in a single file

Jeff Schroeder jeff at neobox.net
Tue Apr 27 13:07:03 MDT 2004


Carl asked:

> Basically what I want is
>   open EntryFile
>   while not EndOfFile(EntryFile)
>   {
>    EntryLine = read EntryFile
>    grep EntryLine LogFile
>   }

How about this:

for line in `cat EntryFile`; do grep $line LogFile; done

To make it a little more user-friendly, add an echo so you know what 
you're looking at:

for line in `cat EntryFile`; do
  echo "Searching for $line"
  grep $line LogFile
done

Note that if EntryFile has spaces in the lines this won't work; $line 
will be set to each *word* rather than each *line*.

HTH,
Jeff



More information about the LUG mailing list