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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)