Bash Code - HTML Table -color value in red if equal to zero

Viewed 42
awk 'BEGIN{print "<table border = 2 > <caption>Number of Codes:</caption> "}
{
    print "<tr>"
        for(i=1;i<=NF;i++){
                    if (i==0){
                        printf "<td><font color=\"red\">%s</font></td>", $i}
                    else{ printf "<td>%s</td>", $i}}
                print "</tr>"}
                END {print "</table>"}'<query_modified_2.txt>output_2.html

My shell script reads a SQL query line by line (query_modified_2) and converts it into an HTML Table (output_2.html). The table contains several rows and columns (5*3); some entries are = to zero. I would like to make all values that are strictly equal to zero in red; I have tried to achieve this in the if statement but the color is not changing.

I have also tried the following :

sed -i "/s//<font color="red">"0"<\/font>/g" output_2.html

However, all zeros are becoming red. for example the 0 in 208 becomes red while I just want to convert cells of the table with 0. Anyway I can adapt one the statements above to meet my goal? I must use bash.

0 Answers
Related