2

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.

3

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

grep foo $(cat s1.txt)
| improve this answer | |
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
| improve this answer | |
  • 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
| improve this answer | |
-1

This will work:

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

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