AWK,管道和尾部-f给出了意外的行为 [英] Awk, pipe and tail -f giving unexpected behavior
问题描述
这是我的示例日志文件. http://pastebin.com/DwWeFhJk .
Here is my sample log file.http://pastebin.com/DwWeFhJk.
我在做什么
tail -f log | awk '{if (NF>3) {print $1}; }'
我得到的结果是正确的
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
64.242.88.10
但是当我做的时候:
tail -f log |
awk '{if (NF>3) {print $1}; }' |
awk '{print $1}'
我没有得到任何输出.甚至没有输出
I am not getting any output. Even no output in case of
tail -f log | awk '{if (NF>3) {print $1}; }' | grep "64"
我不明白为什么第一个awk
的输出没有作为管道后面的第二个awk
/grep
的输入传递的原因.
I am not getting the reason why the output of the first awk
is not getting passed as the input of the second awk
/grep
after the pipe.
推荐答案
当第一个awk
的输出发送到终端时,输出将进行行缓冲,因此每行产生时都会进行打印.当输出进入第二个awk
或grep
时,它将被完全缓冲.在缓冲区已满之前,将不会发送输出.当足够多的额外记录添加到日志时,第二个awk
将缓冲要处理的数据.在那之前,什么都不会发生.
When the output of the first awk
is going to the terminal, the output is line-buffered, so each line is printed as it is produced. When the output is going to the second awk
or the grep
, it is fully buffered. The output won't be sent until the buffer is full. When enough extra records are appended to the log, then the second awk
will a buffer full of data to process. Until then, nothing will happen.
这篇关于AWK,管道和尾部-f给出了意外的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!