News for hackers. Stuff that matters.
Re:New(ish) command line tools by philsnow on Wednesday April 13, 2022 @02:21AM (#31011742)
Also while inside less: & shows you only lines which match a pattern. You can hit & multiple times and less will show you only those lines which match every input pattern. A ^N right after & negates the pattern. & respects the -I switch (case insensitive pattern matching).

I use this all the time, especially when I'm on a machine that I don't want to bother installing something like fzf on.

Re:New(ish) command line tools by hddqsb on Wednesday April 13, 2022 @03:02AM (#31011928)
Good tips. Small correction: `&` only filters by the most recent pattern.
Re:New(ish) command line tools by philsnow on Wednesday April 13, 2022 @09:52AM (#31014666)
Seems to depend on your particular less, see the last sentence of this paragraph from `man less` on my machine:

       &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.  Multiple & commands may be entered, in which case only
              lines which match all of the patterns will be displayed.
Indeed, I thought it would behave like you describe.. when I was refreshing my memory of how the negative pattern filtering worked, I first did &/pattern and then &/^Npattern, and was surprised to see that it displayed zero matching lines.

this is my version of less:

  % less --version
  less 581.2 (POSIX regular expressions)
  Copyright (C) 1984-2021  Mark Nudelman
Re:New(ish) command line tools by hddqsb on Wednesday April 13, 2022 @10:16AM (#31014911)
Oh wow, that's a pretty new feature! It was added in v569, 2020[1].

[1]: https://github.com/gwsw/less/commit/6a070fc53799fb86e0fe3880...