I am writing a bash script in which I need color output. I have a text file that needs to be formatted like this when it's printed to the screen:
>Barry's Whiskey Glass Drink Cup, XL 10 oz Dri... $0.75
example.org/product-page.php?id=1228741
>Cotton Bath Towel Pool Towel Brown - Easy Car... $6.11
example.org/product-page.php?id=1228763
>Cotton Bath Towel Pool Towel Red - Easy Care ... $6.11
example.org/product-page.php?id=1228766
>Mosiso MacBook Case for iPad Pro 12.9/MacBook... $1.95
example.org/product-page.php?id=1228850
The '>....." text needs to be one color, '$..." another color, and "example.org...." light grey. I have tried this:
tac newlist.txt | sed 's/ >/\r\n >/' > bwtext.txt
sed -i 's/>/>\\033\[0;34m/g' bwtext.txt
sed -i 's/\$/\$\\033\[0;33m/g' bwtext.txt
sed -i 's/http/\\033\[0;37mhttp/g' bwtext.txt
while read line
do
echo -e "${line}"
done < bwtext.txt
That inserts the correct escape codes into the file, but when echoed out line by line, instead of processing the codes, it just prints them literally.
>033[0;34mFor Fitbit Alta Accessory Band, Silicone Repl... $033[0;33m1.97
033[0;37mexample.org/product-page.php?id=1247364
>033[0;34mTattify Gradient Nail Wraps - Love Like a Sun... $033[0;33m0.99
033[0;37mexample.org/product-page.php?id=1247367
>033[0;34mEA AromaCare Eucalyptus Essential Oil 120ml/4... $033[0;33m3.00
033[0;37mexample.org/product-page.php?id=1247370
... waiting 10 minutes for next update ...
What am I doing wrong, or how can I do it right? Thanks.