Why no output is shown when using grep twice?

You might also run into a problem with grep buffering when inside a pipe.
ie, you don’t see the output from

   tail --follow=name file.txt | grep something > output.txt

since grep will buffer its own output.

Use the –line-buffered switch for grep to work around this:

tail --follow=name file.txt | grep --line-buffered something > output.txt

This is useful if you want to get the results of the follow into the output.txt file as rapidly as possible.

Leave a Comment