简体   繁体   English

尽管设置了 -f 选项,但似乎 tail 正在缓冲

[英]It seems that tail is buffering though -f option is set

I am writing a script for log parsing, made up with piped tail and grep commands.我正在编写一个用于日志解析的脚本,由管道尾部和 grep 命令组成。 For line numbering purpose, I use a command line which looks like (simplified):出于行号目的,我使用了一个看起来像(简化)的命令行:

tail file_path -f|grep -n "" --line-buffered |tail -n +5|grep -E 'regexpr'

however in that case, the -f option since to be inoperative (tried echo pattern>>file_path in a separate terminal)但是在这种情况下, -f 选项将不起作用(在单独的终端中尝试了echo pattern>>file_path

however, if I change my command to但是,如果我将命令更改为

tail file_path -f|grep -n "" --line-buffered |cat|grep -E 'regexpr'

then it works.然后它工作。 It seems that the second tail command (with +n option to filter first lines) is buffering似乎第二个 tail 命令(使用 +n 选项过滤第一行)正在缓冲

Any idea would be great !任何想法都会很棒!

I solved my issue using stdbuf -oL:我使用 stdbuf -oL 解决了我的问题:

tail file_path -f|grep -n "" --line-buffered | stdbuf -oL tail -n +5|grep -E 'regexpr'

The awk was a working solution but slower than tail|grep awk 是一个可行的解决方案,但比 tail|grep 慢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM