Shell 将表格文件转换为HTML表格
我需要在unix shell脚本中使用html标记以表格格式打印邮件的以下I/p i/p文件:list.txtShell 将表格文件转换为HTML表格,shell,Shell,我需要在unix shell脚本中使用html标记以表格格式打印邮件的以下I/p i/p文件:list.txt a 2019 a 2020 b 2020 b 2001 c 2019 c 2013 我试过了,但我在一列中得到了所有的值: echo "<html> <head> <title>Table Load Status</title> <style> table, t
a 2019 a 2020
b 2020 b 2001
c 2019 c 2013
我试过了,但我在一列中得到了所有的值:
echo "<html>
<head>
<title>Table Load Status</title>
<style>
table, th, td {
border: 1px solid blue;
border-collapse: collapse;
}
th, td {
padding: 5px;
}
</style>
</head>
<body>
<table style='width:100%'>
<tr bgcolor='#808080'>
<th>HEading 1</th>
<th>Heading2</th>
<th>Heading3</th>
<th>Heading4</th>
</tr>"
for contents in $(cat list.txt)
do
echo "<tr>
<td>$contents</td>
<td>$contents</td>
<td>$contents</td>
</tr>"
done
所需O/p:
Heading1 heading2 heading3 heading4
a 2019 a 2020
b 2020 b 2001
c 2019 c 2013
请帮忙。提前感谢编辑:添加一个在HTML输出文件中也添加标题的解决方案,考虑到第一行是标题,如果是这种情况,请尝试以下操作
awk -v s1="\"" '
BEGIN{
print "<html>" ORS "<title>My title goes here...</title>" ORS "<head>"\
ORS "<style>" ORS "table, th, td {" ORS " border: 1px solid black;" ORS\
"}" ORS "</style>" ORS "</head>" ORS "<body>" ORS "<table cellpadding=" s1 "10" s1 ">"
}
FNR==1{
print "<tr>"
for(i=1;i<=NF;i++){
print "<th>" $i "</th>"
}
print "</tr>"
}
{
print "<tr>"
for(i=1;i<=NF;i++){
print "<td>"$i"</td>"
}
print "</tr>"
}
END{
print "</table>" ORS "</body>" ORS "</html>"
}' Input_file
awk -v s1="\"" '
BEGIN{
print "<html>" ORS "<title>My title goes here...</title>" ORS "<head>"\
ORS "<style>" ORS "table, th, td {" ORS " border: 1px solid black;" ORS\
"}" ORS "</style>" ORS "</head>" ORS "<body>" ORS "<table cellpadding=" s1 "10" s1 ">"
}
{
print "<tr>"
for(i=1;i<=NF;i++){
print "<td>"$i"</td>"
}
print "</tr>"
}
END{
print "</table>" ORS "</body>" ORS "</html>"
}' Input_file
awk-v s1=“\”“”
开始{
打印“ORS”我的标题在这里\
ORS“ORS”表格,th,td{“ORS”边框:1px纯黑色;ORS\
}“ORS”“ORS”“ORS”“ORS”
}
FNR==1{
打印“”
对于(i=1;i您正在查看HTML格式的输出吗?抱歉,这不清楚。请您编辑您的问题并提供更多详细信息,然后让我们知道。是的,HTML输出格式为表格格式format@Please在您的问题中发布输出应该是什么样子的,然后让我们知道。我尝试过,但根本不起作用。打印“ORS”视图名称OCE“ORS”“你能不能也提供代码:)@rose,请检查我的编辑答案,然后让我知道?你能帮我吗?
awk -v s1="\"" '
BEGIN{
print "<html>" ORS "<title>My title goes here...</title>" ORS "<head>"\
ORS "<style>" ORS "table, th, td {" ORS " border: 1px solid black;" ORS\
"}" ORS "</style>" ORS "</head>" ORS "<body>" ORS "<table cellpadding=" s1 "10" s1 ">"
}
{
print "<tr>"
for(i=1;i<=NF;i++){
print "<td>"$i"</td>"
}
print "</tr>"
}
END{
print "</table>" ORS "</body>" ORS "</html>"
}' Input_file
<html>
<title>My title goes here...</title>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table cellpadding="10">
<tr>
<td>a</td>
<td>2019</td>
<td>a</td>
<td>2020</td>
</tr>
<tr>
<td>b</td>
<td>2020</td>
<td>b</td>
<td>2001</td>
</tr>
<tr>
<td>c</td>
<td>2019</td>
<td>c</td>
<td>2013</td>
</tr>
</table>
</body>
</html>