Grep a files list

Hi,

I want to grep a string from the list of files present in a text file.
I want the output to be printed only when the string is present in a file along with the file name..

I tried some thing like

cat files_list | grep "search_string" $_

I know $_ is wrong but i want something equivalent of this..

Regards,
nigas

Try:

cat files_list | xargs grep "search_string"

Hi yazu,

Sorry but it resulted in the following message

grep: can't open <file1>
grep: can't open <file2>
grep: can't open <file3>
.
.

Regards,
nigas

I believe you are in a directory where there are no files with paths from your files_list.

Is this what you want:

egrep 'sed' $(cat File_List_File)
  1. Just to be sure, i deleted all the files but for 3 in the files list
  2. opened the files list and "gf" ed it to open the individual files
  3. executed -> cat files_list | xargs grep "search_term"

note: the path of the files contains env variables and i checked that the variables are set, hence that should not be an issue.

---------- Post updated at 10:49 PM ---------- Previous update was at 10:48 PM ----------

@Shell_life : i tried the syntax as you mentioned but it prints out that its a illegal variable name (which i guess is because of the usage of $)

Try this other option:

egrep 'sed' `cat File_List_File`

This is the issue. Try just "cat files_list" and see output. The variables wouldn't expand.