Escaping the '\' character in the replacement string in a sed expression
bash, escaping, sed, string
Solution
Chances are that the `sed` you are using doesn't understand octal, but it may understand hex. Try this version to see if it works for you (using `\x1b` instead of `\033`):
sed "s/ *13) \(.*\)/ \x1b[32m*\x1b[0m \1/"
Problem
I am trying to take a line of text like ``` 13) Check for orphaned Path entries ``` and change it to (I want the bash color codes to colorize the output, not display on the screen) ``` \033[32m*\033[0m Check for orphaned Path entries ``` with bash color codes to colorize the asterisk to make it stand out more. I have a sed command that does most of that, except it doesn't handle the color codes correctly since it sees them as references to replacement text. What I have so far: ``` sed "s/ *13) \(.*\)/ \033[32m*\033[0m \1/" ``` which produces the following output when run on the string I gave at the beginning: ``` 13) Check for orphaned Path entries33[32m* 13) Check for orphaned Path entries33[0m Check for orphaned Path entries ``` It is taking the \0 of the \033 and replacing it with the original string. Doubling the backslashes in the replacement string doesn't make a difference; I still get the same output text. How do I insert bash color escapes into a sed replacement expression?