Buffer records in GNU awk

后端 未结 2 686
囚心锁ツ
囚心锁ツ 2021-01-26 08:09

I\'m trying to make a script that will live watch some logs. I have a log of requests with each request formatted something like this,

---
id=273482
Result=Error         


        
2条回答
  •  一整个雨季
    2021-01-26 08:24

    GNU awk has a fflush() you can use to flush buffers:

    .. | awk 'BEGIN { RS = "---" } /Error/ { print; fflush(); }' | ..
    

    With this you've line buffered all the stages in the pipeline.

    If you in the future have any other programs in the pipeline that don't support something like awk fflush, grep --line-buffered or sed -u, GNU coreutils has a more general stdbuf you can use with any program:

    .. | stdbuf -o 0 any_other_command | ..
    

提交回复
热议问题