Issues with awk scripting for HTML tags

Below is the data file(results) contents-

13450708,13470474,US,15

24954,24845,JPN,44

14258992,14365059,US,4

24954,24845,IND,44

I want to send above data sets to email in a tabular format. For that I am using below awk script. Now the challenge I am facing here is - I want to make the background color as red if the lastfield in the datasets ( i.e. here 15,44,4,44) > 40. Can you please tell me how to use the same in below code.

awk 'BEGIN{

FS=","

print  "<HTML>""<TABLE border="1"><TH>Store_count</TH><TH>Store_sold</TH><TH>Store_code</TH><TH>Backlogs</TH>"

}

 {

printf "<TR>"

for(i=1;i<=NF;i++)

printf "<TD>%s</TD>", $i

print "</TR>"

 }

END{

print "</TABLE></BODY></HTML>"

 }

' results > file1.html

For HTML4 use bgcolor in the <BODY bgcolor=(1,2,3) header -

HTML body bgcolor Attribute

For HTML5 use CSS - bgcolor

Tryit Editor v3.5

<body style="background-color:powderblue;">

Be aware that not all browsers support HTML4.

Also, your example is missing the BODY header

I strongly recommend you not use table tags.

Better to use divs, even in email.

Also, I recommend you avoid any style attribute in your elements and instead include a small <style> tag with CSS; but I understand when you have just a small amount of style, why you would like to use the style attribute, but all the pros use CSS.

1 Like