The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 01-07-2009
moldoverb moldoverb is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 5
using foreach with while loop

I want to search line-by-line for a string in a file, and I want to do this to a series of files in a directory. I'm doing this in tcsh

This works fine to do the search:

while read i; do grep $i file2; done <file1.txt

This also works fine to read a directory:

foreach file ('/bin/ls *.txt')
echo $file
end

but if I try and combine the two, no joy.

foreach file ('/bin/ls *.txt')
while read i; do grep $i file2; done <$file
end

Help please!

Last edited by moldoverb; 01-07-2009 at 03:35 PM..