Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Alternatively, you can use less(1) in tail mode to search growing logs.

  less +F -p pattern /path/to/log
(Ctrl-C to break out of tail mode. /pattern to interactively set search pattern.)


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.


Good tips. Small correction: `&` only filters by the most recent pattern.


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


Oh wow, that's a pretty new feature! It was added in v569, 2020[1].

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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: