Tail has the following options:
-f The -f option causes tail to not stop when end of file is reached, but rather to wait for additional data to be appended to the input. The -f option is ignored if the standard input is a pipe, but not if it is a FIFO.
I'd like to only grep for something
in the tail output.
tail -f <FILE> | grep <SOMETHING>
Issue is it only run grep once and is done. No other output happens. How can I make grep run correctly with the -f
?
You can use grep with -A n option to print N lines after matching lines. Using -B n option you can print N lines before matching lines. Using -C n option you can print N lines before and after matching lines.
It is possible to print a line above or below (or both) a line having a pattern using grep by using -A , -B or -C flags with num value. Here num denotes the number of additional lines to be printed which is just above or below the matched line.
You will find another SO Question helpful: How to 'grep' a continuous stream?
Turn on grep's line buffering mode.
tail -f file | grep --line-buffered my_pattern
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With