2

This question already has an answer here:

I have Sample file s1.txt like this:

  Sample.log.54
  Sample.log.56
  Sample.log.57
  Sample.log.58
  Sample.log.59
  Sample.log.110
  Sample.log.113
  Sample.log.114
  Sample.log.115
  Sample.log.116
  Sample.log.117
  Sample.log.118
  Sample.log.119
  Sample.log.120
  Sample.log.121
  Sample.log.122
  Sample.log.112
  Sample.log.123
  Sample.log.124
  Sample.log.140

In the folder i have many other files. but i need to grep particular string from the files that are listed in s1.txt. I should not read all the files which are present in the folder.

marked as duplicate by Julie Pelletier, don_crissti, Jeff Schaller, Gilles shell Aug 26 '16 at 22:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

If you need to grep for foo in the files and are using bash, you can use:

grep foo $(cat s1.txt)
2

If each line within s1.txt represents a file name and file names have no funky characters in them:

<s1.txt xargs -d '\n' grep string
  • For avoiding (a) word splitting on spaces and tabs and (b) pathname expansion: +1. – John1024 Aug 26 '16 at 19:43
0

This question is answered on stack overflow ([https://stackoverflow.com/questions/14655717/grepping-from-a-text-file-list][1]).

xargs grep "your pattern" < my-file-list.txt
-1

This will work:

for i in `cat s1.txt`; do cat $i | grep "your-string-to-search"; done

Not the answer you're looking for? Browse other questions tagged or ask your own question.