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.