How to combine greps on log files opened with tail -f

Updated . Posted . Visible to the public.

In order to chain greps on log files that are opened via tail -f test.log you have to use the --line-buffered command line option for grep.

Imagine you have the following content in your log file.

# content for log/test.log
test foo
bar
test foo bar baz
bla

Now if you would like to grep for lines that contain foo but not bar, you can use the following command chain:

$ tail -f log/test.log | grep --line-buffered "foo" | grep -v "bar"

Output:
test foo    
Ulrich Berkmüller
Last edit
Keywords
chain, multiple
License
Source code in this card is licensed under the MIT License.
Posted by Ulrich Berkmüller to makandra dev (2012-01-27 09:42)