1

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

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

Cool .. but cat email.html | sendmail -t [email protected] doesn't work am not able to recieve the output with tables
2

-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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.