When I type

memcached -vv 2>&1 | grep --color=always "SET\|GET"

I get nice memcached stats

GET AR-City-1

GET rest-part-241

SET rest-part-241 Value len is 685

GET main-rest-list-1

It would be great to pipe this to something, and color GET in green instead of the default red.

How could I do that?


This could be probably written shorter but solution gives the result:

memcached -vv 2>&1 | sed -e "s/^GET.*$/\x1b[31m&\x1b[0m/" | sed -e "s/^SET.*$/\x1b[32m&\x1b[0m/"

Or if you wish with background colors instead of foreground color:

memcached -vv 2>&1 | sed -e "s/^GET.*$/\x1b[41m&\x1b[0m/" | sed -e "s/^SET.*$/\x1b[42m&\x1b[0m/"

So GET is green, SET is red.

  • If you want to use sed I think you can use sed one time and you can skip using of grep: `sed -n -r "/SET|GET/ s@SET...@replace_what_you_want@p ; s@GET...@replace_what_you_want@p" – uzsolt Nov 18 '11 at 15:39
  • I worked on this a little, this is solution: memcached -vv 2>&1 | sed -e "s/GET.*/\x1b[32m&\x1b[0m/" | sed -e "s/SET.*/\x1b[31m&\x1b[0m/" | grep "GET\|SET" # thx! – dux Nov 18 '11 at 17:22

for gnu grep this will work:

$ export GREP_COLOR="01;32"

where "01" means: bold and "32" green. The default is "01:31" (bold red). Other colors:

  • 31:red
  • 32:green
  • 33:yellow
  • 34:blue
  • 35:purple

These colors may look different depending on how your terminal is configured, but those above are the standard colors.


$ env | grep GREP_COLORS

gives you a result, those settings supersede the GREP_COLOR setting (note the "S"), see the grep manage for more detailed settings using GREP_COLORS.

  • thx for the answer, settings works well in a way that default color now is green, but I do not have SET in red and GET in green as sad in question. – dux Nov 18 '11 at 16:42

try rpen a text highlighter based on egrep :)


If you want to see different words in different colors then use colorize for example


Another alternative text colorizer based on ack-grep:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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