Read more

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

Ulrich Berkmueller
January 27, 2012Software engineer

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.

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

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    
Posted by Ulrich Berkmueller to makandra dev (2012-01-27 10:42)