HI am trying to convert a text file to html with table so that i could mail the output in a table format and i used awk 'BEGIN{print "Content-Type: text/html; charset="us-ascii""\n "<html>"\n "<Body>"\n "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print \n</Body>"\n "</html>"\n"</table>"}' a.txt >> email.html but am having problems could some one help me on this
Add a comment
|
2 Answers
You need to clean your line. The \n need to be in double quote like this:
awk '
BEGIN{
print "Content-Type: text/html; charset=us-ascii\n <html>\n <Body>\n<table>"
}
{print "<tr>"
for(i=1;i<=NF;i++)
print "<td>" $i"</td>"
print "</tr>"
}
END{
print "\n</Body>\n</html>\n</table>"
}' a.txt >> email.html
1 Comment
Sathish
Cool .. but
cat email.html | sendmail -t [email protected] doesn't work am not able to recieve the output with tables-Edited- It works with this:
awk '
BEGIN{
print "Content-Type: text/html; charset="us-ascii"\n<html>\n<head>\n<style>\ntable , th,td\n{\n border:1px solid black;
border-collapse:collapse;\n}\n</style>\n</head>\n<Body>\n<table>"
}
{print "<tr>"
for(i=1;i<=NF;i++)
print "<td>" $i"</td>"
print "</tr>"
}
END{
print "\n</table>\n</Body>\n</html>\n"
}' a.txt >> email.html