[lug] finding text lines in a single file

Wagner, Carl Carl.Wagner at Level3.com
Tue Apr 27 13:04:18 MDT 2004


Hi,

I know someone can answer this in about 10 seconds, but I am having a brain lock.

I have a text file with 1 entry per line.  I want to grep a file for each successive entry, using
a bash/ksh script.


Example:
EntryFile
   123
   124
   125
   126

I want to grep for each entry in a single log file
   grep 123 LogFile
   grep 124 LogFile
   grep 125 LogFile
   grep 126 LogFile

I tried 
  grep `xargs -n 1 -t < EntryFile` LogFile
But that is looking for a file named 123

I tried 
	xargs -n 1 -t < EntryFile egrep LogFile
but that is not what I wanted either.

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


I could do this easily in c, but I need to be able to do it in a script.

Thanks,
Carl.



More information about the LUG mailing list