Thursday, November 17, 2011

Remove color codes (special characters) with sed

Terminal - Remove color codes (special characters) with sed

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

Remove color codes (special characters) with sed

Removes ANSI color and end of line codes to the [{attr1};...;{attrn}m format.

Alternatives

sed -r "s/\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]//g
Remove color codes (special characters) with sed

Removes ANSI color and end of line codes to the [{attr1};...;{attrn}m format.

sed -r "s:\x1B\[[0-9;]*[mK]::g"'

cat input.txt | sed 's/\\\033[^a-zA-Z]*.//g'

src:::http-colon--slash--slash-www.commandlinefu.com-slash-commands-slash-view-slash-3584-slash-remove-color-codes-special-characters-with-sed