Grep a files list


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep a files list
# 1  
Old 07-21-2011
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
Code:
cat files_list | grep "search_string" $_

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

Regards,
nigas

Last edited by Franklin52; 07-21-2011 at 03:57 PM.. Reason: Please use code tags for data and code samples, thank you
# 2  
Old 07-21-2011
Try:
Code:
cat files_list | xargs grep "search_string"

# 3  
Old 07-21-2011
Hi yazu,

Sorry but it resulted in the following message
Code:
grep: can't open <file1>
grep: can't open <file2>
grep: can't open <file3>
.
.

Regards,
nigas

Last edited by Franklin52; 07-21-2011 at 03:58 PM.. Reason: Please use code tags for data and code samples, thank you
# 4  
Old 07-21-2011
I believe you are in a directory where there are no files with paths from your files_list.
# 5  
Old 07-21-2011
Is this what you want:
Code:
egrep 'sed' $(cat File_List_File)

# 6  
Old 07-21-2011
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 $)
# 7  
Old 07-21-2011
Try this other option:
Code:
egrep 'sed' `cat File_List_File`

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

List files in dir and grep accordingly

bash or c-shell On Solaris 10 I need a command that will list the files of a directory, and grep each of those filenames out of a static text file, and then only echo field 2 of the static text file. Something like this: #> ls -1 /home/dir/ | each filename grep $filename static.txt |awk... (4 Replies)
Discussion started by: ajp7701
4 Replies

2. UNIX for Dummies Questions & Answers

Grep for list of files with only found hits

Hi, With grep -ci word * I get a list of files either they have a hit, or the have not (0). I wanted to pipe to a new list of files, which only shows the files where the string was found, and counted, not the whole bunch. How to do this? Any advice welcome! with best regards, Omar... (11 Replies)
Discussion started by: OmarKN
11 Replies

3. Shell Programming and Scripting

I'm trying 2 copy files after using the grep to get a list

for XmlFileName in ${xmlFileNames} do XmlFileName=$(echo $XmlFileName | sed 's|./||') # Remove leading ./ path that find command prefixes to filenames cp $XmlFileName $NEW_DIR/ done (1 Reply)
Discussion started by: emc^24sho
1 Replies

4. Shell Programming and Scripting

Grep string in files and list file names that contain the string

Hi, I have a list of zipped files. I want to grep for a string in all files and get a list of file names that contain the string. But without unzipping them before that, more like using something like gzcat. My OS is: SunOS test 5.10 Generic_142900-13 sun4u sparc SUNW,SPARC-Enterprise (8 Replies)
Discussion started by: apenkov
8 Replies

5. Shell Programming and Scripting

Take a list if strings from a file and search them in a list of files and report them

I have a file 1.txt with the below contents. -----cat 1.txt----- 1234 5678 1256 1234 1247 ------------------- I have 3 more files in a folder -----ls -lrt------- A1.txt A2.txt A3.txt ------------------- The contents of those three files are similar format with different data values... (8 Replies)
Discussion started by: realspirituals
8 Replies

6. Homework & Coursework Questions

list of files modified 10 hours ago using grep

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Here is the question: Make a list of files in your home directory that were changed less that 10 hours ago,... (3 Replies)
Discussion started by: fight4love
3 Replies

7. UNIX for Dummies Questions & Answers

list all files containing 4 digit number using grep

how can i list all files in my home directory that have a 4 digit id number, the line number where the id is located and the id itself not printing the entire line? (5 Replies)
Discussion started by: hobiwhenuknowme
5 Replies

8. Shell Programming and Scripting

grep for certain files using a file as input to grep and then move

Hi All, I need to grep few files which has words like the below in the file name , which i want to put it in a file and and grep for the files which contain these names and move it to a new directory , full file name -C20091210.1000-20091210.1100_SMGBSC3:1000... (2 Replies)
Discussion started by: anita07
2 Replies

9. Shell Programming and Scripting

find list of files from a list and copy to a directory

I will be very grateful if someone can help me with bash shell script that does the following: I have a list of filenames: A01_155716 A05_155780 A07_155812 A09_155844 A11_155876 that are kept in different sub directories within my current directory. I want to find these files and copy... (3 Replies)
Discussion started by: manishabh
3 Replies

10. UNIX for Dummies Questions & Answers

counting a list of string in a list of txt files

Hi there! I have 150 txt files named chunk1, chunk2, ........., chunk150. I have a second file called string.txt with more than 1000 unique strings, house, dog, cat ... I want to know which command I should use to count how many times each string appears in the 150 files. I have tried... (4 Replies)
Discussion started by: Pep Puigvert
4 Replies
Login or Register to Ask a Question