This question already has an answer here:

I need a command that colorizes some symbol sequence in output of a certain command. I'd like it like grep make it.

$ some-command | grep symbol-sequence

However grep removed lines that isn't contained symbol-sequence. I'd like to have all original lines with highlighted symbol-sequence. How it can be done?

I have alias grep='grep --color=auto' in ~/.bashrc

marked as duplicate by manatwork, devnull, Bernhard, Anthon, slm Apr 9 '14 at 14:36

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • add an --color=always at the end of the line – Valentin Bajrami Apr 9 '14 at 12:56
  • @val0x00ff Good point, but this doesn't solve the OP's problem who would like to have also the lines that don't match in the output. – lgeorget Apr 9 '14 at 13:03
  • @val0x00ff - Thank you. However, I have colorized output always. I expanded question – Loom Apr 9 '14 at 13:08

You can do that using the ANSI control characters:

some-command | sed 's/symbol-sequence/^[[0;32;2m symbol-sequence^[[0;0m/'

The characters ^[ are not a regular ^ followed by a regular [. It is an unprintable character. You can get it on most terminal by typing Ctrl-v Ctrl-Esc. The second [ is a real [ though.

If you prefer full-ascii, here is a copy-pastable version which has the same effect:

some-command | sed 's/symbol-sequence/\x1B[0;32;2m symbol-sequence\x1B[0;0m/'

You can change the "32" and the "2" in the above command to change the colors and style in the output. Look for "ANSI escape sequences" in any search engine for details and color codes.

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