Buffer records in GNU awk

后端 未结 2 684
囚心锁ツ
囚心锁ツ 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 | ..
    
    0 讨论(0)
  • 2021-01-26 08:26

    Here is the fix

    tail -f requestLog|awk 'BEGIN{RS="--*"}/Error/{split($1,a,"=");print a[2]}'
    
    0 讨论(0)
提交回复
热议问题