Matthieu Napoli Matthieu Napoli - 7 months ago 27
Bash Question

How to 'grep' a continuous stream?

Is that possible to use

grep
on a continuous stream?

What I mean is sort of a
tail -f <file>
command, but with
grep
on the output in order to keep only the lines that interest me.

I've tried
tail -f <file> | grep pattern
but it seems that
grep
can only be executed once
tail
finishes, that is to say never.

tad tad
Answer

Turn on grep's line buffering mode.

tail -f file | grep --line-buffered my_pattern