In Unix "less", can I jump to the next line that does NOT contain X?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Dream Voyager Looping
--
Chapters
00:00 In Unix &Quot;Less&Quot;, Can I Jump To The Next Line That Does Not Contain X?
00:28 Accepted Answer Score 36
00:53 Answer 2 Score 5
01:16 Answer 3 Score 2
01:40 Thank you
--
Full question
https://superuser.com/questions/195077/i...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#unix #grep #less
#avk47
ACCEPTED ANSWER
Score 36
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
.
ANSWER 2
Score 5
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.
ANSWER 3
Score 2
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 &!^Computing
then 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.