Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 07-28-2005, 10:52 PM   #1
Registered: Feb 2004
Posts: 307

Rep: Reputation: 30
Weird tail + grep bug

I just found a weird bug in the way tail and grep work together. I've tested this on Slackware -current and Fedora Core 2. Run this code in your terminal:

$ echo bob jones > bob
$ tail -n 1 | grep bob | grep bob
bob jones
$ tail -fn 1 | grep bob
bob jones
$ tail -fn 1 | grep bob | grep bob
The last command outputs NOTHING!. This should output "bob jones" like the others, what is going on?

I just noticed this while tailing my syslog file, watching iptables' output.

I know this used to work, so when did this all of a sudden happen?

This only happens with the "-f" option, and two piped greps to it. (Note: the -n 1 isn't really needed)
Old 07-29-2005, 02:09 AM   #2
Registered: Aug 2004
Location: The Netherlands
Distribution: RedHat 2, 3, 4, 5, Fedora, SuSE, Gentoo
Posts: 372

Rep: Reputation: 42
you forgot the filename 'bob' on the tail command line, but okay..

Further, the tail -f tries to follow on a file and passes information in chunks to the grep, and grep does the same ..

To my knowledge, if you put some more lines in 'bob' you WOULD see something, but perhaps not EVERYTHING. the content is stuck in some buffer held to be processed once more info is getting into the file bob while tail is being watching it.

I am not an expert on the way tail and grep work, but I'd say it isn't a bug, but rather you're experiencing the buffered output each program has..
Old 12-15-2006, 05:30 AM   #3
LQ Newbie
Registered: Nov 2003
Posts: 6

Rep: Reputation: 0
I hit a similar problem, a mate managed to solve it, you need to add --line-buffered to any grep thats piping to another, so in your example (with the filename added in):

tail -fn 1 bob | grep --line-buffered bob | grep bob

I realise this is an old post, so sorry for resurrecting it, but just in case other people find it like I did with google, thought it might help...


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto tail -f /var/log/messages | grep isdninfo Mopp Programming 4 07-22-2011 10:00 AM
Weird installer bug? MaTrIx709 Debian 2 07-15-2005 03:06 PM
Help pls!!! grep or tail->restart poj Linux - Software 3 11-26-2004 12:50 AM
Amusing/Weird KDE 3.3 bug or error paradoxdruid Linux - Software 15 02-18-2004 10:43 PM
Weird Konqueror problem (a bug?) ivanatora Linux - Software 1 10-13-2003 03:02 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration