员工信息:
Name Age DOB
______ ___ _________
Jones 54 06/12/1998
Allen 50 06/09/1990
我想在表格中看到上面的输出。
答案1
按照 RalfFriedl 的建议使用html
:
<table>
<tr>
<th>Name</th>
<th>Age</th>
<th>DOB</th>
</tr>
<tr>
<td>Jones</td>
<td>54</td>
<td>06/12/1998</td>
</tr>
<tr>
<td>Allen</td>
<td>50</td>
<td>06/09/1990</td>
</tr>
</table>
为了使用类似的东西发送 HTML 电子邮件,sendmail
您需要有一个 html 电子邮件标头。为此,我使用临时文件来存储如下内容:
[email protected]
[email protected]
mailsub='This is the subject of my email'
curdate=$(date "+%a, %d %b %Y %H:%M:%S %z")
html_header="From: <${mailfrom}>\nTo: <${mailto}>\nSubject: ${mailsub}\nDate: <${curdate}>\nContent-Type: text/html; charset=utf-8\n"
echo -e "$html_header" > tmp_file
这将创建一个像这样的标题:
From: <[email protected]>
To: <[email protected]>
Subject: This is the subject of my email
Date: <Sun, 12 Aug 2018 12:30:17 +0000>
Content-Type: text/html; charset=utf-8
然后您可以将表添加到文件中并cat tmp_file | mail -t
答案2
1)作为ascii:
#!/bin/bash
prtline(){
printf "%-10.10s %3.3s %12.12s\n" $1 $2 $3
}
prtline Name Age DOB
prtline _______ __________ ___________
prtline Jones 54 06/12/1998
prtline Allen 50 06/09/1990
2)作为html表:
echo "<table>"
echo "<tr><td>Name</td><td>Age</td><td>DOB</td></tr>"
echo "<tr><td>Jones</td><td>22</td><td>1821</td></tr>"
#etc
echo "</table>"
3) 与 tbl/groff/ps2pdf。这将为您提供可预测的良好结果,但可能会更复杂一些。您必须将 pdf 作为附件发送。
答案3
使用以下代码将 CSV 文件转换为 HTML:
安装nawk
以使用此代码
nawk 'BEGIN{
FS=","
print "<p>Hi,<br/><br/>"
print "Please find the Employee details.<p>"
print "<HTML>""<TABLE border="1"><TH>Name</TH><TH>Age</TH><TH>DoB</TH>"
}
{
printf "<TR>"
for(i=1;i<=NF;i++)
printf "<TD>%s</TD>", $i
print "</TR>"
}
END{
print "</TABLE>"
print "<p><br/>Thank You,<br/>"
print "Team HR<p>"
print "</BODY></HTML>"
}
' employeedetails.csv > employeeDetails.html