[Mac/Terminal] I'm trying to replace words in a sentence with red-colored versions of them. I'm trying to use sed, but it's not outputting the result in the format I'm expecting. i.e.
for w in ${sp}; do
msg=`echo $msg | sed "s/$w/\\033[1;31m$w\\033[0m/g"`
done
results in:
033[1;31mstb033[0m 033[1;31mshu033[0m 033[1;31mkok033[0m
where $sp is a list of a subset of words contained in $msg
the desired output would look like:
\033[1;31mstb\033[0m \033[1;31mshu\033[0m \033[1;31mkok\033[0m
and then my hope would be that echo -e would interpret this correctly and show the red coloring instead. So far, however, I seem to not understand quite correctly how sed works in order to accomplish this.