Dynamically change grep with less/tail

339 Views Asked by At

when tailing a log file, we might use:

tail -f foo.log | grep bar

if we want to change the grep argument, we have to ctrl-c and then change the argument and then restart the command.

my question is - is there a way to dynamically change what we are grepping for without having to kill the tail/grep commands?

Also looking for a way to do this with less instead of tail if possible.

1

There are 1 best solutions below

0
On

I get that you are after a filtered, autoscrolling view of something.

The less man page states this about the F command:

Scroll forward, and keep trying to read when the end of file is reached. Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the "tail -f" command.)

And the following about the & command

Display only lines which match the pattern; lines which do not match the pattern are not displayed. If pattern is empty (if you type & immediately followed by ENTER), any filtering is turned off, and all lines are displayed. While filtering is in effect, an ampersand is displayed at the beginning of the prompt, as a reminder that some lines in the file may be hidden.

Note that these are less commands, not command line switches.

You still have to abort the autoscrolling to change the pattern, but you do so without actually leaving less.