I've written a bunch of scripts to colorize matches, like this:
$ echo abcdef | grepg c ab[green]c[/green]def $ echo abcdef | grepr e abcd[red]e[/red]f
It also works when I chain it:
$ echo abcef | grepr a | grepg b | grepg c | grepp e | grepl f abcdef [each letter have it's own style]
Hovewer when I try this for digits, the result is wrong:
$ echo 12345 | grepr 1 | grepg 2 | grepb 3 | grepp 4 | grepl 5 [01;[01;3[01;35m4m31m1[01;[01;3[01;35m4m32m2[01;3[01;35m4m3[01;35m45
because if subsequent greps also match inside the escape sequences produced by earlier greps.
How to do it right? I need either to stop grep matching inside terminal escale sequences or make it match more than one pattern and colorize them to different colours.