Using grep with tail. Unix challenge!


#1

I want to tail my development.log file, but i only want to show the
lines that have the word “ERROR” in. How can i do this??

Doing this :
tail -f development.log | grep “ERROR”
will filter the log file, but it will not constantly update itself. i.e.
newly added lines to the log file that contain “ERROR” are not
displayed.

Does anyone know how to do this?

Thanks
Chris


#2

“Chris” == Chris removed_email_address@domain.invalid writes:

Doing this :
tail -f development.log | grep “ERROR”
will filter the log file, but it will not constantly update itself.

Oh, it does update. It just doesn’t show the results to you as often
as you’d like. The problem is that grep will use its normal I/O
buffers, which are suited for reading from and writing to files. If
you’re using GNU or FreeBSD grep, try giving the --line-buffered
option to it.

	     Calle D. <removed_email_address@domain.invalid>
	 http://www.livejournal.com/users/cdybedahl/
          Please pay no attention to the panda in the fridge.

#3

Yeah that works,
thanks
Chris


#4

On Jun 5, 2006, at 6:47 AM, Calle D. wrote:

option to it.

       Calle D. <removed_email_address@domain.invalid>
   http://www.livejournal.com/users/cdybedahl/
          Please pay no attention to the panda in the fridge.

If you have ‘less’, you can do:

less -p’ERROR’ development.log

and use the ‘F’ command to follow the end like ‘tail -f’ does. This
has the added benefit of being able to break out of the ‘Waiting…’
and peruse the log for a bit before continuing with another ‘F’.

-Rob

Rob B. http://agileconsultingllc.com
removed_email_address@domain.invalid
+1 513-295-4739