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
Aia
May 21, 2014, 10:59pm
2
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
aia:
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
Aia
May 22, 2014, 12:01am
4
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
sidnow
May 22, 2014, 10:00am
5
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>
Aia
May 29, 2014, 6:29pm
7
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.
sidnow
June 4, 2014, 10:54pm
9
Chubler_XL...you are the man!!!that was exactly what I was looking for