I'm tailing a log file with -f flag. Then I'm piping this to grep, to find only lines that contain "X". That's working perfectly fine.
Now I want to pipe this again into another grep, that will remove all the lines containing "Y". When I add the second pipe, the file stop refreshing and it looks like no data is coming.
This is the command that works: tail -f my_file.log | grep "X"
This is the command that doesn't: tail -f my_file.log | grep "X" | grep -v "Y"
How should I structure this so that the command works?
Best Answer
As the output of
grep
is buffered, use--line-buffered
option ofgrep
to enable line buffering:If your
grep
does not have the option, you can usestdbuf
as an alternative: