grep and tail -f?
Using GNU tail
and GNU grep
, I am able to grep a tail -f
using the straight-forward syntax:
tail -f /var/log/file.log | grep search_term
Add --line-buffered
to grep
, and that may reduce the delay for you. Very useful in some cases.
tail -f foo | grep --line-buffered bar
It will work fine; more generally, grep
will wait when a program isn't outputting, and keep reading as the output comes in, so if you do:
$ (echo foo; sleep 5; echo test; sleep 5) | grep test
Nothing will happen for 5 seconds, then grep will output the matched "test", and then five seconds later it will exit when the piped process does