Skip to main content
3 events
when toggle format what by license comment
Dec 17, 2020 at 16:20 comment added wardw Also just a note that the colors are reset with \e[0m after the match and so this will also clear any existing colorization in the input stream. That's also true of grep, however. If you need to handle input that's already colorized, you might consider wrapping your match text with the terminal controls tput smso and tput rmso instead.
Dec 17, 2020 at 16:16 comment added wardw I like this solution because it does just what you want rather than bend and existing tool like grep which is more indirect. It also gives you more flexibility should you want to change the behavior. (Although just a note you can change the colors with grep with the env var GREP_COLORS which uses the same SGR codes).
Jul 24, 2011 at 4:23 history answered iconoclast CC BY-SA 3.0