Help to process each line in a file...

Hi all,

I am storing all the fil names from a directory into a file "filenames.txt" like using awk and cut commands
base/src/file1.sc
base/src/file2.sc
base/src/file3.sc
base/src/file4.sc
base/src/file5.sc
base/src/file6.sc
base/src/file7.sc
base/src/file8.sc
base/src/file9.sc

and then I need to pick the 1st line from this file and need to grep for a particular pattern inside this and need to continue till the last record in file "filenames.txt", but I am stuck not knowing how to process each record from this file "filenames.txt"... I appreciate your effort in helping me.. :slight_smile:

one way -

while read filename
do
      grep 'what i want to find' $filename
done  < file_with_filenames_in_it

Does grep pattern `cat filenames.txt` not do what you want? Note those are backticks (ASCII 96), not regular apostrophes.

using for loop

for i in `cat filenames.txt`
do
..
grep .......... $i
..
done
Using while loop

while read line
do
..
grep ....... $line
..
done < filenames.txt

Thanks
Penchal

cat filenames.txt | xargs grep pattern

Thanks everyone for your quick response, I will try the solutions provided and will post the response... :slight_smile:

That's a Useless Use of Cat.

xargs grep pattern <filenames.txt

Thanks era and boddu :), am able to achieve what I really wanted using xargs grep pattern<filenames.txt, Thanks a lot.....