不能使用awk管道输出
函数awk '!seen[$0]++'
在输入管道中打印新的事件。
然而,我无法添加管道。 例如
my_function_with_ouput | awk '!seen[$0]++' | while read j do echo $j done
不产生任何输出。
awk
缓冲STDOUT流,你需要刷新STDOUT,使用GNU awk
的fflush()
函数刷新流:
my_function_with_ouput | awk '!seen[$0]++ {print; fflush()}' | while ...
如果你没有gawk
,请从stdbuf
,unbuffered STDOUT获取帮助:
my_function_with_ouput | stdbuf -o0 awk '!seen[$0]++' | while ...
或者STDOUT行缓冲:
my_function_with_ouput | stdbuf -oL awk '!seen[$0]++' | while ...