Reputation: 3119
I'm filtering an Apache log, but concatenating multiple filters I got no output. Trying to reduce the issue to a minimal example it seems that grep is unable to forward the output to the pipe
$ tail -F access_log | grep test
10.108.57.6 - - [03/Nov/2017:12:35:55 +0000] "GET /test HTTP/1.1" 404 202 "-" "curl/7.11.0 (i686-pc-linux-gnu) libcurl/7.11.0 OpenSSL/1.0.2d ipv6 zlib/1.1.3" 161
$ tail -F access_log | grep test | grep test
# nothing
$ tail -F access_log | grep test | sed 's/test/asd/g'
# nothing
$ tail -F access_log | sed 's/test/asd/g' | grep asd
10.108.57.6 - - [03/Nov/2017:12:44:58 +0000] "GET /asd HTTP/1.1" 404 202 "-" "curl/7.11.0 (i686-pc-linux-gnu) libcurl/7.11.0 OpenSSL/1.0.2d ipv6 zlib/1.1.3" 143
Any light?
I'm on a Centos 7.2, with grep 2.20
Upvotes: 2
Views: 630
Reputation: 6960
For grepping stream (tail -f
)
it's almost always better to use grep --line-buffered
instead of just grep
From official docs:
--line-buffered Use line buffering on output. This can cause a performance penalty.
In other words: Write output each time when grep get input and do not wait for filling grep buffer
Upvotes: 3