How to 'grep' a continuous stream?

前端 未结 12 1503
清酒与你
清酒与你 2020-11-22 11:15

Is that possible to use grep on a continuous stream?

What I mean is sort of a tail -f command, but with grep on t

12条回答
  •  臣服心动
    2020-11-22 11:31

    you certainly won't succeed with

    tail -f /var/log/foo.log |grep --line-buffered string2search
    

    when you use "colortail" as an alias for tail, eg. in bash

    alias tail='colortail -n 30'
    

    you can check by type alias if this outputs something like tail isan alias of colortail -n 30. then you have your culprit :)

    Solution:

    remove the alias with

    unalias tail
    

    ensure that you're using the 'real' tail binary by this command

    type tail
    

    which should output something like:

    tail is /usr/bin/tail
    

    and then you can run your command

    tail -f foo.log |grep --line-buffered something
    

    Good luck.

提交回复
热议问题