Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How can I search for newlines (or end of lines) as part of a search using less?

For example, I'd like to search for length=9\n, but don't want to merely search for length==9 because that'd get matches for length=90\n.

I'm using GNU bash, version 4.0.33(1)-release (x86_64-pc-linux-gnu) on Ubuntu 9.10 (Karmic Koala)

I tried reading the friendly manual, but it said

/pattern

Search forward in the file for the N-th line containing the pattern. N defaults to 1. The pattern is a regular expression, as recognized by the regular expression library supplied by your system. The search starts at the second line displayed (but see the -a and -j options, which change this).

and I don't know how to RTFM beyond that.

share|improve this question
1  
You might also find searches anchored to word boundaries to be useful. /\<length=9\> will find "length=9" that's anywhere on a line without matching "length=90" or "stringlength=9". See man 7 regex and man grep for more. –  Dennis Williamson Dec 20 '10 at 0:46
1  
For those looking for an answer to the question's title: I don't believe you can include newlines in a search in less. This means that multiline searches in less do not appear to be possible. –  drevicko Aug 28 '12 at 5:17
add comment

1 Answer

up vote 6 down vote accepted

You can do:

/pattern$

The pattern replacing pattern, but the $ must stay, it tells the search to look for the pattern, and then the end of the line.

So you'd do:

/length=9$
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.