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 > UNIX for Dummies Questions & Answers
.
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
foreach question

OK, so I am extremely rusty and am just getting back to Unix after 9 years.

I'm stuck on something easy. 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.

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!