I use this old script, names hilite.pl, taken from the web, already with the "unknown author" line!
#!/usr/bin/perl -w
### Usage: hilite <ansi command> <target string>
### Purpose: Will read text from standard input and perform specified highlighting
### command before displaying text to standard output.
### License: GNU GPL
# unknown author
$|=1; # don't buffer i/o
$command = "$ARGV[0]";
$target = "$ARGV[1]";
$color = "\e[" . $command . "m";
$end = "\e[0m";
while(<STDIN>) {
s/($target)/$color$1$end/;
print $_;
}
Then i can use it in pipes, to "hilite" log output or other things, using regexp/PCRE:
echo 'hello color world!!' | hilite.pl 34 "[Hh]el[^ ]*" | hilite.pl 43 .orld | hilite.pl 32 "\scolor\s"
This will paint hello in blue, color in green and world in yellow background
You can see the color list with (you can expand the bash expression to {01..255} if you want):
for i in {01..10} {30..49} {90..110} ; do echo $i | hilite.pl $i $i ; done
grc
worked this way rather than as a prefix command.