Created
September 29, 2018 23:17
-
-
Save cyklee/ef7197be4558bf9fb9a31a8973227e6d to your computer and use it in GitHub Desktop.
Sequential grep that preserves the order of the list of patterns provided
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/21908809/grep-f-file-to-print-in-order-as-a-file | |
# You can pipe patt.grep (pattern) 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. | |
# foobar here is the placeholder | |
# This is useful as grep | |
cat patt.grep | xargs -Ifoobar grep foobar myfile.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment