Reputation: 1124
How I should delete all color-controlling sequences (or even all unprintable sequences) from string in Bash?
For example, I have got a string with color swithcers:
a="\e[0;31m->\e0m"
If i will echo it like
echo -e "$a"
there will be printed two colored characters ->
- the string i want to get without any color.
In my actual situation, I am getting colored string building in script, so I can't just hardcode the result as a constant and I don't want to double the size of script to build both colored and uncolored results.
If answer will delete all escape-sequences, not only coloring ones, it will be okay. String can contain Unicode.
Upvotes: 1
Views: 86
Reputation: 4551
$ a="\e[0;31m->\e0m"
$ echo $a | sed 's/\\e[^m]*m//g'
->
Something like this?
Upvotes: 2