Hacker News new | ask | show | jobs
by philo23 960 days ago
A little bit off topic, but I’ve always wanted a “simple” CLI tool that works exactly like grep (same flags and regex support), but rather than filtering the result, it just highlights the matches in the output.

I’ve not found anything like that yet though, closest I’ve come is using grep with the before/after/context flag with a high number of lines or using search in less, but I want to do something like...

    tail -f access.log | highlight ".jpg"
Maybe I’ve just not found the right flag for grep yet...

Edit: Thank you everyone for your suggestions, you've all been very helpful! And apologies again for hijacking the topic, tailspin looks very neat.

4 comments

This is how I colorize with grep:

  cat <file> | grep -E --color "<regex>|$"
Where `<regex>` is your pattern.
adding "or an end of the line" to the regex is pretty clever, I'm stealing it :) thanks!
Obligatory “you don’t need cat”
ripgrep has a --passthru flag that does exactly this

  tail -f access.log | rg --passthru '\.jpg'
Brilliant, this looks like exactly what I want. I already use ripgrep a lot, so I should have guessed it had this feature already but wouldn't have known what to search for to find it! Thank you
I have that aliased to `hl` in my bashrc
As does ack
I wrote this years ago: https://github.com/jes/emph
A Markdown README and some screenshots will really help.
Try

| less -p ".jpg"