Sample Header Ad - 728x90

How to interpret escape characters in a string and display them as newlines, color etc

-1 votes
2 answers
139 views
i grep something like:
str='"a\nb"'
echo ${str} | grep -E -o '".*"'
and got:
"a\nb"
i wish the result displays like:
a
b
how could this be done? thanks p.s. actually, the str is
str='"\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\r\33[1A\33[K\33[32m[58,378 / 59,145]\33[0m 12 actions running\n    Compiling interface/detail/type_support.c; 5s linux-sandbox\n    Compiling interface/detail/type_c.cpp; 5s linux-sandbox\n    ; 2s linux-sandbox ...\n"'
i think the \33[...part is related to color on shell, which is more complicated...could the \n and \r as well as color display as human-readable by grep or jq?
Asked by furynerd (21 rep)
Aug 23, 2024, 09:21 AM
Last activity: Aug 23, 2024, 02:14 PM