grep inside less?

Written by:

I’m currently sifting through a lot of unfamiliar logs looking for some issues. The first file I look at is Events.log, and I get at least three pages in less which appear to display the same event at different times – an event that appears to be fairly benign.
I would like to filter this event out, and currently I quit less and do something like

grep -v "event text" Events.log | less

This now brings a number of other common, uninteresting events that I would also like to filter out. Is there a way I can grep -v inside of less? Rather than having to do

egrep -v "event text|somethign else|the other thing|foo|bar" Events.log | less

It strikes me as a useful feature when looking at any kind of log file – and if less isn’t the tool, is there another with the qualities I seek? Just a less-style viewer with built in less.

forquare

less has very powerful pattern matching. From the man page:

  &pattern
          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.

Also use /pattern to search (and n/N to go to next/previous).

orion

grep inside less?
0 votes, 0.00 avg. rating (0% score)

Leave a Reply