Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .