Loop over the list of files and grep
:
while read -r file; do
grep runcob "${file}"
done < scripts.txt
Question
I have a list of files in a file called scripts.txt
I want to grep for "runcob" only in the files contained in scripts.txt. I dont want to grep in other files that are not contained in scripts.txt. How do I do so. Please help. I am planning to use ksh if we need a script for this
Solution 2
Loop over the list of files and grep
:
while read -r file; do
grep runcob "${file}"
done < scripts.txt
OTHER TIPS
This is why we have xargs
.
xargs grep 'runcob' <scripts.txt
If the filenames do not contain any spaces, it could be as simple
grep runcob $(cat scripts.txt)