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

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -