In Unix "less", can I jump to the next line that does NOT contain X?

Solution 1:

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.

Solution 2:

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.

Solution 3:

Not only can you jump between lines that don't contain X, you can hide the lines that do contain X, using less's & regex filter command.

less file.conf

then type &!^Computingthen the enter key and all those line will be hidden from view.

You can still search within the remaining lines with /.

Once you find the line you want you can bring the others back if you need their context - type & then the enter key to remove the filter.