[后台进程正在写入日志,我想将此日志中的所有文本输出到终端,直到单词“ Do”为止。
我正在使用此命令:
tail -f service.log | sed '/Do/ q'
由于某种原因,该命令将输出单词“ Do”,并等待直到下一行写入日志之前退出。
为了验证,我运行了命令,然后在另一个窗口中使用以下命令将其手动附加到文件:
echo A >> service.log
# outputs 'A' in the sed window
echo B >> service.log
# outputs 'B' in the sed window
echo C >> service.log
# outputs 'C' in the sed window
echo Do >> service.log
# outputs 'Do' in the sed window, but the tail and sed command is still running.
echo E >> service.log
# now the tail and sed command finishes.
sed似乎仅在将下一行写入文件后才退出,而不是在输出时退出。
如何使我的sed命令在单词'Do'的第一个输出上退出?
尝试使用大写字母Q
sed '/Compiled/Q'