diff --git a/README.md b/README.md index f5b73f5..d1830a5 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/unix/apply-successive-filters-to-lines-in-less.md b/unix/apply-successive-filters-to-lines-in-less.md new file mode 100644 index 0000000..719eb17 --- /dev/null +++ b/unix/apply-successive-filters-to-lines-in-less.md @@ -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.