Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've written a bunch of scripts to colorize matches, like this:

$ echo abcdef | grepg c
$ echo abcdef | grepr e

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

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.

share|improve this question

1 Answer 1

Take a look at lookkbehind and lookahead in regexes.

Something like


could work (I'm not sure about the format of the colorizing strings)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.