
Update: about col handle tabs and space //mentioned by 〇. Perl -pe 's/\e\*m(?:\e\[K)?//g' # Adam Katz's trickĮxample with OP's command line: perl -e 'use Term::ANSIColor print color "white" print "ABC\n" print color "reset" ' \Īs pointed out by Stuart Cardall's comment, this sed command line is used by the project Ultimate Nginx Bad Bot (1000 stars) to clean up the email report -) Adam Katz suggests to use \e (same as \x1b) in PCRE.Ĭhoose your regex depending on how much commands you want to filter: perl -pe 's/\e\*m//g' # Remove colors only The command perl has the advantage of being generally easier to install/update on more operating systems. The version of sed installed on some operating systems may be limited (e.g. Do not forget to redirect gcc 2>&1 | sed.

M Graphics Rendition Mode (including color)īritton Kerin indicates K (in addition to m) removes the colors from gcc error/warning. Sed 's/\x1b\*//g' # Remove color and move sequences sed 's/\x1b\*//g' # Remove color and move sequences Michał Faleński and Miguel Mota propose to remove only some escape sequences using and respectively. Tom Hale suggests to also remove all other escape sequences using instead of just the letter m specific to the graphics mode escape sequence (color): sed 's/\x1b\*//g' # Remove all escape sequencesīut may be too wide and could remove too much. (OP means Original Poster) perl -e 'use Term::ANSIColor print color "white" print "ABC\n" print color "reset" ' |įlag -e is optional for GNU sed but required for the macOS default sed: sed 's/\x1b\*m//g' # Remove color sequences only The macOS default sed does not support special characters like \e as pointed out by slm and steamer25 in the comments.

\x1b (or \x1B) is the escape special character.The characters ^[[37m and ^[[0m are part of the ANSI escape sequences (CSI codes).
