multiple programs reading a single stream

So i had to grep multiple patterns into their own files from one stream and had forgotten about this and was trying to do this with awk & sed (which got very ugly really fast). instead, we just need tee, grep, and bash extensions.

example:

tee <srv1_20140912.log >(grep "access" >20140912_access.txt) >(grep "fail" >20140912_fail.txt)

lets clean that up:

tee <srv1_20140912.log \
>(grep "access" >20140912_access.txt) \
>(grep "fail" >20140912_fail.txt)

lets clean that up a little more with generic file names:

tee <original_file.log \
>(grep "pattern 1" >file_one.txt) \
>(grep "pattern 2" >file_two.txt)

The nice part about this is that you can add as many patterns as you need to output to the files that are needed.

«
»

    Leave a Reply

    Your email address will not be published. Required fields are marked *