Remove color codes (special characters) with sed

sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"

By: Cowboy
2009-09-23 12:06:33

10 Alternatives + Submit Alt

What Others Think

See also for other possible codes to strip
pixelbeat · 596 weeks and 3 days ago
Just what I needed for cleaning the capture of the 'script' command. Thanks!
funollet · 590 weeks and 5 days ago
Does this work when you have 2 colors on a line?
matthewbauer · 590 weeks and 1 day ago
badass. nice seddage :) i wonder if there is a simpler way to do it with simple redirection of stdout.. hmm not sure yet. anyway awesome, i'm using this for now xD
kevinquinnyo · 473 weeks ago
FWIW, the `-r` does not work with `sed` on Mac OS-X.
jaytaylor · 400 weeks and 2 days ago
Is there any way to undo the effect of sed command?
Wajiha · 357 weeks and 6 days ago
jessicacoles · 20 weeks and 3 days ago
Recently i have found this website and it is one of the best learning platforms for students nowadays. They can Don Julio Real Extra Anejo Tequila easily learn the commands from here. Various opinions from experts are listed here and you can also ask any kind of doubts here. They will definitely provide a clear solution for all your doubts.
Alyssalauren · 1 week and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: