bash-tail -f进入grep切割不能正常工作

我正在尝试构建一个 shell脚本来监视一些日志文件.
我正在使用如下命令:
tail -f /var/somelog | grep --line-buffered " some test and p l a c e h o l d e r" | cut -f 3,4,14 -d " "

日志文件如下:

some test and p l a c e h o l d e r 3
some test and p l a c e h o l d e r 4
some test and p l a c e h o l d e r 5
some test and p l a c e h o l d e r 6

等等..
我的问题是命令的输出不显示最后一行

some test and p l a c e h o l d e r 6

直到行

some test and p l a c e h o l d e r 7

添加到日志中.

我希望我明白我的问题.任何人都可以帮我解决这个问题吗?
谢谢 :)

问题几乎肯定与grep和cut如何缓冲输出有关.这是一个黑客,应该让你解决问题,虽然我相信有更好的方法来做到这一点:
tail -f /var/somelog | while read line; do echo "$line" | grep "some test and p l a c e h o l d e r" | cut -f 3,14 -d " "; done

(不要忘记;完成命令结束)

或者,因为gawk不缓冲它的输出,你可以使用它代替剪切,以避免繁琐的循环:

tail -f log | grep --line-buffered "some test and p l a c e h o l d e r" | gawk '{print $3,$4,$14}'

查看http://www.pixelbeat.org/programming/stdio_buffering/有关缓冲问题的更多信息.

相关文章

用的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补全...