When watching a growing log file with e.g. "less -iS +F service.log" I want to limit the display to lines matching a certain pattern.
I tried something like
less +F service.log | grep <pattern> | less +F
which doesn't work. Also
cat < service.log | grep <pattern> | less +F
doesn't do what I want. It looks like the input is already closed and less doesn't show changes.
How can I limit the display to lines matching a certain pattern?
In signal processing, a filter is a device or process that removes some unwanted components or features from a signal. Filtering is a class of signal processing, the defining feature of filters being the complete or partial suppression of some aspect of the signal.
The FILTER function allows you to filter a range of data based on criteria you define.
On the Data tab, in the Sort & Filter group, click Advanced. To filter the list range by copying rows that match your criteria to another area of the worksheet, click Copy to another location, click in the Copy to box, and then click the upper-left corner of the area where you want to paste the rows.
Filter a range of data Select any cell within the range. Select Data > Filter. Select Text Filters or Number Filters, and then select a comparison, like Between. Enter the filter criteria and select OK.
This question is ages old, but I still think it's worth adding a solution. Instead of trying to grep first and then use less, what about using filtering inside less?
In brief:
use less +F
on your fileCTRL-C
to temporarily break the "following" action&
and your pattern to enable filtering+F
to re-enable the "following" actionMore details on this answer on the Unix&Linux StackExchange
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With