且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

管道尾部输出虽然用grep两次

更新时间:2023-12-04 12:30:22

我相信这里的问题是,第一个是grep的缓冲,这意味着第二个grep的将不会看到它,直到缓冲区将刷新输出。

I believe the problem here is that the first grep is buffering the output which means the second grep won't see it until the buffer is flushed.

尝试添加 - 行缓冲选项你的第一个grep的:

Try adding the --line-buffered option on your first grep:

tail -f access_log | grep --line-buffered "127.0.0.1" | grep -v ".css"

有关更多信息,请参见BashFAQ / 009 - 什么是缓冲或者说,为什么我的命令行中不产生输出:尾-f日志文件| grep的'富巴| awk的...

For more info, see "BashFAQ/009 -- What is buffering? Or, why does my command line produce no output: tail -f logfile | grep 'foo bar' | awk ..."