linux - How can I grep in a loop? -
i have file containing text in separate lines.
text1 text2 text3 textn i have directory many files. want grep each line in of specific directory. easy way this?
there no need loop, can use grep -f option patterns file:
grep -f pattern_file files* from man grep:
-f file, --file=file
obtain patterns file, 1 per line. empty file contains 0 patterns, , therefore matches nothing. (-f specified posix.)
test
$ cat a1 hello how you? $ cat a2 bye hello $ cat pattern hello bye $ grep -f pattern a* a1:hello a2:bye a2:hello
Comments
Post a Comment