1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-12 11:38:01 +00:00

Add Apply Successive Filters To Lines In Less as a Unix TIL

This commit is contained in:
jbranchaud
2026-01-07 19:14:52 -06:00
parent 4801e730f9
commit 087766a792
2 changed files with 35 additions and 1 deletions

View File

@@ -0,0 +1,33 @@
# Apply Successive Filters To Lines In Less
Let's say I've opened a large Rails log file with `less`:
```bash
$ less logs/development.log
```
I have an idea of what I'm looking for, but there is way more noise than signal.
I can start to filter out some of the noise. The `&` command starts a filter
prompt. If I start to filter by something like `INSERT INTO`, then a ton of
lines disappear leaving just those matching that pattern.
Scrolling through the current set of lines, I start to have a better idea of
what I'm looking for, but there is still too much noise. I can apply an
additional successive filter on the remaining lines by hitting `&` again and
entering in another pattern -- e.g. `GoodJob`.
Now I only see lines that contain both `INSERT INTO` and `GoodJob` somewhere in
them.
As `less` puts it:
> Multiple & commands may be entered, in which case only lines which match all
> of the patterns will be displayed.
If I want to undo all the filtering, I just need to enter an empty `&` filter
prompt and it will reset things back to displaying all lines.
> If pattern is empty (if you type & immediately followed by ENTER), any
> filtering is turned off, and all lines are displayed.
See `man less` for more details.