简体   繁体   中英

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. 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)

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

Any idea would be great !

I solved my issue using 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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