Piping of grep is not working with tail?

Dude

I am trying to debug one scenario by checking the logs, here is my command

tail -f eclipse.log | grep 'enimation' | grep  -i 'tap'

Basically what I am trying to to is that, of all of the line, I am printing lines with enimation in it, then of all of the animation, I want to see the animation with "tap" in it.

Here is the sammple data for which it is returning empty results

*******enimation error*********TapExpand
*******enimation error*********TapShrink

This is returning empty results.

While if I run this command

 tail -f eclipse.log | grep  -i 'enimation.*tap'

it returns correct results. Can someone please explain to me, what is the difference between the above two command and why there is a discrepancy in the results. They both seem identical to me.

anubhava

grep is buffering it's output. To tell GNU grep to spit out output line-by-line you need to use --line-buffered option in grep to make it work:

tail -f eclipse.log | grep --line-buffered 'enimation' | grep --line-buffered -i 'tap'

As per man grep:

--line-buffered
    Force output to be line buffered.  By default, output is line buffered when standard
    output is a terminal and block buffered otherwise.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related