Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k
Source Link
acm
  • 583
  • 1
  • 4
  • 5

Using sed to color the output from a command on solaris

I have a ksh script that must work on both linux and solaris. I'm trying to color the output of specific commands. It works on linux (specifically RHEL6), but not on solaris (SunOS 5.10).

Command on linux (the output "test" is correctly colored red):

[amartin@linuxbox:~]$ echo "test" | sed 's,.*,\x1B[31m&\x1B[0m,'
test

Command on solaris (the output "test" is not colored):

[amartin@sunbox:~]$ echo "test" | sed 's,.*,\x1B[31m&\x1B[0m,'
x1B[31mtestx1B[0m

Is there a way to craft this command such that the output is red, without the raw codes in the output? I can't change the 'echo' command because that's just a fill in for the command I'm actually running.