How to grep a continuous stream, with paging

I posted this to Superuser but got no takers: https://superuser.com/questions/832578/how-to-grep-a-continuous-stream-with-paging

I want to take a log file and filter out some irrelevant log entries, like ones at the INFO level. The above Stack Overflow answer got me part of the way:

$ tail -f php_error_log | grep -v INFO

The next piece I want is to have paging in this stream, such as with less. less +F works on continuous streams but I can't apply that to grep. How can I accomplish this?


Since posting that question I worked on it and discovered that less is waiting for the EOF to appear, and hangs until it receives it (source). This explains why trying to follow a pipe is not working. I hacked up a short script to do what I want, inelegantly:

#!/bin/bash
tail -f /data/tmp/test.txt | grep --line-buffered foo > /data/tmp/foo &
pid=$!
echo $pid
sleep 1
less +F /data/tmp/foo
kill $pid
rm /data/tmp/foo

I'm convinced it's possible to do this more elegantly, perhaps with a temp file that is automatically cleaned up without direct interaction.


Solution 1:

How about this:

grep -V INFO php_error_log | less +F

Or, you can run multitail php_error_log, then once multitail starts, press e and follow the prompts to add a regular expression to filter on. For continuous monitoring of one or more log files over time, multitail is a good solution.