Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In the Unix less tool, is it possible to jump to the next line that does not contain a certain expression?

I sometimes have to look through files that contain thousands of similar adjacent lines that, for example, all say "Computing something" and I'm interested in the next line after the current block, which does not contain the word "Computing".

share|improve this question
up vote 17 down vote accepted

Yes, this is non-match search functionality, for example:

less file.conf

then you type / and after that ! your last line should look like:

Non-match /

then type your pattern for example Non-match /^# to look for first line without beginning #

Instead of ! character you can also use Ctrl+N.

share|improve this answer
+1 nifty, never heard of that – sleske Oct 2 '10 at 11:21
This is perfect. Couldn't have expected a better answer. – dehmann Oct 3 '10 at 5:30

As an addition to Casual Coder's answer:

You could also filter out the lines altogether:

<logfile grep -v mypattern |less 

The disadvantage is that you have to quit and restart grep to change the pattern; the advantage is that the lines you don't want to see are hidden, which makes it easier to spot interesting patterns in the lines that you are interested in.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .