1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-09 01:58:02 +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

@@ -10,7 +10,7 @@ working across different projects via [VisualMode](https://www.visualmode.dev/).
For a steady stream of TILs, [sign up for my newsletter](https://visualmode.kit.com/newsletter).
_1721 TILs and counting..._
_1722 TILs and counting..._
See some of the other learning resources I work on:
@@ -1609,6 +1609,7 @@ If you've learned something here, support my efforts writing daily TILs by
### Unix
- [All The Environment Variables](unix/all-the-environment-variables.md)
- [Apply Successive Filters To Lines In Less](unix/apply-successive-filters-to-lines-in-less.md)
- [Authorize A cURL Request](unix/authorize-a-curl-request.md)
- [Cat A File With Line Numbers](unix/cat-a-file-with-line-numbers.md)
- [Cat Files With Color Using Bat](unix/cat-files-with-color-using-bat.md)

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.