[lug] finding text lines in a single file

Joey McDonald joey at scare.org
Tue Apr 27 14:37:29 MDT 2004


And another way to do it would be: 

  perl -e 'for (123 .. 126) { `grep $_ LogFile` }'

	--joey

On Tue, Apr 27, 2004 at 01:04:18PM -0600, Wagner, Carl wrote:
> 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.
> _______________________________________________
> 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 portf67 channel=#colug



More information about the LUG mailing list