2

I'd like to have a pager program, similar to less, with the following added commands:

  • Prompt for a regular expression and display only lines that match it;
  • Prompt for a regular expression and remove from the current display lines that match it; and
  • Revert to showing the entire file.
  • Show the current filters.

Another nice feature would be an optional visual indication that lines have been hidden.

Filtering the input to `less, as in:

grep pattern filename | less

is only a partial solution. It's missing the ability to easily reconfigure the filtering without exiting and restarting the pager.

I'm looking for something that works in text mode, though a GUI tool would also be helpful.

I've taken a quick look at the most pager, and it doesn't seem to have such a feature.

Ideally I'd like to see this as a new feature in a future release in less. I might contact the maintainer with a suggestion. Meanwhile, does such a thing already exist?

6

Well, this is a little embarrassing.

I suggested this feature to Mark Nudelman, the maintainer of the less command. His response:

Is there something in this request that isn't already handled by the & command?

I've somehow managed to use less for several decades without noticing that that command exists.

Here's the documentation:

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

Certain characters are special as in the / command:

^N or !
Display only lines which do NOT match the pattern.

^R
Don't interpret regular expression metacharacters; that is, do a simple textual comparison.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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