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

Remove color codes (special characters) with sed


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

11 Alternatives + Submit Alt

What Others Think

See also http://www.pixelbeat.org/scripts/ansi2html.sh for other possible codes to strip
pixelbeat · 452 weeks and 1 day ago
Just what I needed for cleaning the capture of the 'script' command. Thanks!
funollet · 446 weeks and 2 days ago
Does this work when you have 2 colors on a line?
matthewbauer · 445 weeks and 6 days 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 · 328 weeks and 5 days ago
FWIW, the `-r` does not work with `sed` on Mac OS-X.
jaytaylor · 256 weeks ago
Is there any way to undo the effect of sed command?
Wajiha · 213 weeks and 3 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?

commandlinefu.com 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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: