正则表达式 – grep的管道不适用于尾部?

参见英文答案 > How to ‘grep’ a continuous stream?                                    11个
我试图通过检查日志来调试一个场景,这是我的命令

tail -f eclipse.log | grep 'enimation' | grep  -i 'tap'

基本上我想要的是,在所有的线条中,我在其中打印带有enimation的线条,然后在所有动画中,我想看到带有“tap”的动画.

以下是返回空结果的sammple数据

*******enimation error*********TapExpand
*******enimation error*********TapShrink

这将返回空结果.

如果我运行此命令

 tail -f eclipse.log | grep  -i 'enimation.*tap'

它返回正确的结果.有人可以向我解释一下,上述两个命令之间的区别是什么以及为什么结果存在差异.它们看起来都和我一模一样.

解决方法:

grep正在缓冲它的输出.要告诉GNU grep逐行吐出输出,你需要在grep中使用–line-buffered选项来使它工作:

tail -f eclipse.log | grep --line-buffered 'enimation' | grep --line-buffered -i 'tap'

按照男人的说法:

--line-buffered
    Force output to be line buffered.  By default, output is line buffered when standard
    output is a terminal and block buffered otherwise.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...