[TriLUG] Learn something new every day.

Brian Daniels bitmage at bellsouth.net
Mon Feb 20 16:28:57 EST 2006


Maybe this one is common knowledge, but it caught me off guard.  And it might 
save somebody some time.

Assume we have a logfile.  To watch it on your terminal, you 
could type 'tail -f logfile'.

To filter the output, you could use 'tail -f logfile | grep foo'.

All as expected.  But you want more filtering, so you type:
'tail -f logfile | grep foo | grep bar'

And get no output at all, even though there are log entries that contain both 
foo and bar!

It turns out that a pipe has a buffer of 4096 characters and is holding the
data.  To make it work, you need:
'tail -f logfile | grep --line-buffer foo | grep bar'
and now you get the filtered output as expected.

--Brian


-- 
I think my life is fuller because I realize
that I don't know what I'm doing.
I'm delighted with the width of the world!
			---Richard Feynman


Brian Daniels                  bitmage at bellsouth.net
      http://www.eviloverlord.net




More information about the TriLUG mailing list