Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter function for less +F

Tags:

less-unix

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?

like image 344
axelrose Avatar asked Nov 19 '09 09:11

axelrose


People also ask

What is the function of filter?

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.

What is filter function in Excel?

The FILTER function allows you to filter a range of data based on criteria you define.

How do I filter a condition in Excel?

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.

Where is the filter function in Excel?

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.


1 Answers

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:

  1. use less +F on your file
  2. CTRL-C to temporarily break the "following" action
  3. Type & and your pattern to enable filtering
  4. Issue +F to re-enable the "following" action

More details on this answer on the Unix&Linux StackExchange

like image 64
Jir Avatar answered Sep 25 '22 02:09

Jir