We have a bash script running on prod. Occasionally we receive control characters inside the bash script as output which is sent somewhere else to be rendered.
Is there any way using tr/awk/sed
or anything else to translate/convert control characters from (0-1f) (hex) to unicode escaping (\u0000 - \u0037)(octal) [except for newline "\n"]
- We do not want to use perl (ord) inside the bash script. (Increases cpu usage)
- We do not want to remove the control characters (makes the output look ugly)
Simple Example:
echo "Hello, this \n is a new line. This \t is a tab"
Should become:
Hello, this
is a new line. This \u0011 is a tab
Reference:
ASCII table: http://www.asciitable.com/
Control Characters: https://en.wikipedia.org/wiki/Control_character