Why no output is shown when using grep twice?

后端 未结 5 849
心在旅途
心在旅途 2020-12-02 16:46

Basically I\'m wondering why this doesn\'t output anything:

tail --follow=name file.txt | grep something | grep something_else 

You can ass

5条回答
  •  抹茶落季
    2020-12-02 17:39

    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.

提交回复
热议问题