Tuesday, January 12, 2016

Linux - sed to clean up "color codes" or escape sequence

If you see

drwxr-xr-x   23 abc xyz          4096 May 24  2011  [00;34m. [00m/
drwxrwsr-x    4 abc xyz          4096 May  3 01:14  [00;34m.. [00m/

in your directories, you could use the following to remove the color code.

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


1. http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed

Sed - Example guide

sed is a very useful stream editor to perform search and replace. Below are some useful tip 1. Usage sed 's/apple/orange/' file...