Create table within awk-if statement

Hi I am trying to create a table within an awk if statement

awk -F, '{ if ($8 ~ /Match/)
BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' SN1.csv | mailx -s "Your details" abc@123.com

But this doesnt work..

Please suggest

Add the pair of brackets highlighted and see if that would work.

awk -F, '{ if ($8 ~ /Match/)
BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++){print "<td>" $i"</td>"};print "</tr>"} END{print "</table>"}' SN1.csv | mailx -s "Your details" abc@123.com

Your code still wrong

Correct like this..

awk -F, '
                          BEGIN{
                                      print "<table>"
                               }
                               {
                                       if($8 ~ /Pattern to match/)
                                       {
                                           print "<tr>"
                                           for(i=1;i<=NF;i++)
                                           {
                                                 print "<td>" $i "</td>"
                                           }
                                           print "</tr>"
                                       }
                              }
                           END{ 
                                     print "</table>"
                              }
        ' Inputfile.csv |  mailx -s "Your details" abc@123.com
awk -F, 'BEGIN{print "<table>"} $8 ~ /Match/ {print "<tr>"; for(i=1;i<=NF;i++){ print "<td>" $i"</td>"};print "</tr>"} END{print "</table>"}' SN1.csv | mailx -s "Your details" abc@123.com

Hi Thanks guys, script runs, but it gives me with tags. I tried putting sendmail -t at the end instead of mailx, but it still gives me with tags. Any suggestions?

<table>
<tr>
<td>data1</td>
<td>data2</td>
<td>data3</td>
<td>data4</td>
<td>data5</td>
</tr>
</table> 

Any one any ideas??

Assuming that you are referring that the html is not showing as html but as text when you send it via sendmail.

You need to tell about Content-Type

Content-Type: text/html

Personally, whoever invented the sending of html in emails should be very proud of it NOT! That's how far I am willing to go with it.

Take a look at the awk script I posted Here for an example of sending tables as email.

Chubler_XL...you are the man!!!that was exactly what I was looking for