i writing bash script in need color output. have text file needs formatted when it's printed 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 ipad pro 12.9/macbook... $1.95 example.org/product-page.php?id=1228850
the '>....." text needs 1 color, '$..." color, , "example.org...." light grey. 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 echo -e "${line}" done < bwtext.txt
that inserts correct escape codes file, when echoed out line line, instead of processing codes, 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 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 next update ...
what doing wrong, or how can right? thanks.
you have correct escape sequences in file not being read in while loop. try adding raw input flag ( -r ) while reading not interpret escape sequences , give desired formatting.
while read -r line echo -e "${line}" done < bwtext.txt