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.


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.

The following two tabs change content below.

charlie root

VP of keeping it real / HNIC at pissedoffadmins.com
I bring the cold coffee.

Latest posts by charlie root (see all)

No Comment.

Add Your Comment