Skip to main content
7 of 9
insert duplicate link

Redirecting without color

Possible Duplicate:
Removing control chars (including console codes / colours) from script output

How do I disable all color codes when redirecting to file?

I previously asked how to redirect everything to file, now I want to know how to redirect without colors.

So instead of:

^[(B^[[m^[[1m^[[31m:: ^[(B^[[m^[[1mDaemon script ^[(B^[[m^[[1m^[[31mntpd^[(B^[[m^[[1m does not exist or is not executable.^[(B^[[m

I'm looking forward to achieve plain:

:: Daemon script ntpd does not exist or is not executable.

###Update: Looking at jw013 provided link, I tried the sed approach:

rc.d restart ntpd | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" &> progress.txt

But it didn't even redirect, and simply displayed the colored output to the console.

###Update 2: After user1146332 comment, in order to pipe STDERR, I have to pipe with |&.

rc.d restart ntpd | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" &> progress.txt

Resulted in:

^[(B:: ^[(BDaemon script ^[(Bntpd^[(B does not exist or is not executable.^[(B

It's tidier, but still some codes remain. But that sed RegExp is too hard for me to decypher.

tomsseisums
  • 427
  • 1
  • 5
  • 13