grep -f file to print in order as a file
bash, grep, linux, shell
Solution
You can pipe `patt.grep` to `xargs`, which will pass the patterns to `grep` one at a time.
By default `xargs` appends arguments at the end of the command. But in this case, `grep` needs `myfile.log` to be the last argument. So use the `-I{}` option to tell `xargs` to replace `{}` with the arguments.
cat patt.grep | xargs -Ihello grep hello myfile.log
Problem
I have a a requirement to grep patterns from a file but need them in order. ``` $ cat patt.grep name1 name2 $ grep -f patt.grep myfile.log name2:some xxxxxxxxxx name1:some xxxxxxxxxx ``` I am getting the output as name2 was found first it was printed then name1 is found it is also printed. But my requirement is to get the name1 first as per the order of patt.grep file. I am expecting the output as ``` name1:some xxxxxxxxxx name2:some xxxxxxxxxx ```