Skip to content

Instantly share code, notes, and snippets.

@cyklee
Created September 29, 2018 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyklee/ef7197be4558bf9fb9a31a8973227e6d to your computer and use it in GitHub Desktop.
Save cyklee/ef7197be4558bf9fb9a31a8973227e6d to your computer and use it in GitHub Desktop.
Sequential grep that preserves the order of the list of patterns provided
# 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