我正在尝试使用awk命令以html表格式发送邮件,如下所示:
(
echo "From: "
echo "Subject: testing of html table using awk"
awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' file.tmp
) | sendmail xxx@yy.com
Run Code Online (Sandbox Code Playgroud)
我的文件(file.tmp)包含如下:
AAA 1 1 1 1 0 0
SAP 1 1 1 1 0 0
RTTC 1 1 1 1 0 0
PGW 1 1 1 1 0 0
Run Code Online (Sandbox Code Playgroud)
但我没有以html表格格式获取邮件,而是使用html代码本身.
AWK命令是否正确?或者我错过了什么?
您需要添加Content-type标题:
(
echo "From: "
echo "Subject: testing of html table using awk"
echo "Content-type: text/html"
echo
awk 'BEGIN{print "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table>"}' file.tmp
) | sendmail xxx@yy.com
Run Code Online (Sandbox Code Playgroud)