How to 'grep' a continuous stream?

前端 未结 12 1500
清酒与你
清酒与你 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:29

    Turn on grep's line buffering mode when using BSD grep (FreeBSD, Mac OS X etc.)

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

    You don't need to do this for GNU grep (used on pretty much any Linux) as it will flush by default (YMMV for other Unix-likes such as SmartOS, AIX or QNX).

提交回复
热议问题