[lug] finding text lines in a single file

Wagner, Carl Carl.Wagner at Level3.com
Tue Apr 27 13:15:02 MDT 2004

That should do it.

Like I said, about 10 seconds.


-----Original Message-----
From: lug-bounces at lug.boulder.co.us
[mailto:lug-bounces at lug.boulder.co.us]On Behalf Of Jeff Schroeder
Sent: Tuesday, April 27, 2004 1:07 PM
To: Linux Users Group
Subject: Re: [lug] finding text lines in a single file

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

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

Web Page:  http://lug.boulder.co.us
Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
Join us on IRC: lug.boulder.co.us port=6667 channel=#colug

More information about the LUG mailing list