Re: Highlighting CLI output: what are these terms called?
On Wed, Apr 17, 2013 at 8:17 PM, Bob Proulx <firstname.lastname@example.org> wrote:
> The only regexp replacement in the right hand side is "$&". The
> perlre docs say:
> man perlre
> $& returns the entire matched string. (At one point $0 did
> also, but now it returns the name of the program.)
> This comes from use in 'sed'. In sed the docs say:
> man sed
> Attempt to match regexp against the pattern space. If
> successful, replace that portion matched with replacement. The
> replacement may contain the special character & to refer to
> that portion of the pattern space which matched, and the
> special escapes \1 through \9 to refer to the corresponding
> matching sub-expressions in the regexp.
> And can be used like this:
> $ echo fore | sed 's/fore/be&/'
> All of the \e [ (escape bracket) patterns are terminal escape sequence
> colors as the others mentioned. Personally I find using them like
> that annoying since they are non-portable. It would be better to use
> 'tput' to generate those from the terminfo data instead.
>> tail -f file.log | perl -pe 's/keyword/\e[1;31;43m$&\e[0m/g'
> Instead of that I would be inclined to use grep's --color option.
> Same thing but easier to type and remember.
> tail -f file.log | grep --color keyword
Thank you Bob. I like how you get to the source (sed) and to the
problem (use grep). Very informative, and I'll be reading this post a
few times over.