2 回答

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊
假設(shè)您的輸出存儲(chǔ)在/tmp/output.txt中,請(qǐng)嘗試以下操作:
./yourscript.sh > /tmp/output.txt
awk -F ':' 'BEGIN { print "<html>\n<body>\n<table>\n\t<tr>" } { print "\t\t<th>"$1"</th>" } END { print "\t</tr>" }' /tmp/output.txt
awk -F ':' 'BEGIN { print "\t<tr>" } { print "\t\t<td>"$2"</td>" } END { print "\t</tr>\n</table>\n</body>\n</html>" }' /tmp/output.txt
返回
<html>
<body>
<table>
<tr>
<th>Directory Name</th>
<th>Business Date</th>
<th>Expected_files_1</th>
<th>Expected_files_2</th>
<th>Actual_files_1</th>
<th>Actual_files_2</th>
<th>Comments of Actual_files_1</th>
<th>Comments of Actual_files_2</th>
<th>Comments Other</th>
</tr>
<tr>
<td> /a/b/c</td>
<td> 20200323</td>
<td>2</td>
<td>14</td>
<td> File count changes each day</td>
<td> File count changes each day</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
如果您確保腳本輸出的每一行都具有相同的key: value格式,那么您會(huì)更輕松。如果您與我們分享您的腳本,我們可能會(huì)為您提供進(jìn)一步幫助。

TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
這是一個(gè)兩步過(guò)程:
將列轉(zhuǎn)置為行,使用冒號(hào)作為輸入/輸出分隔符:
awk -f tst.awk inputfile.txt > result.txt
tst.awk 包含以下代碼:
BEGIN { FS=OFS=":" }
{
for (rowNr=1;rowNr<=NF;rowNr++) {
cell[rowNr,NR] = $rowNr
}
maxRows = (NF > maxRows ? NF : maxRows)
maxCols = NR
}
END {
for (rowNr=1;rowNr<=maxRows;rowNr++) {
for (colNr=1;colNr<=maxCols;colNr++) {
printf "%s%s", cell[rowNr,colNr], (colNr < maxCols ? OFS : ORS)
}
}
}
用于將點(diǎn) 1 的輸出轉(zhuǎn)換為 html 表格格式:有一個(gè)簡(jiǎn)單的腳本可用于執(zhí)行此操作:https: //sourceforge.net/projects/command-output-to-html-table/可用于轉(zhuǎn)換任何命令輸出或文件為漂亮的 html 表格格式。您可以為此腳本指定分隔符,包括制表符、換行符等特殊分隔符,并通過(guò)頂部的 html 搜索獲取 html 表格格式的輸出。只需下載腳本,解壓并發(fā)出以下命令:
cat result.txt | { cat ; echo ; } | ./tabulate.sh -d ":" -t "My Report" -h "My Report" > output.html
這里 : 作為分隔符。
我在這里附加了一個(gè)示例output.html:https ://sourceforge.net/projects/my-project-files/files/output.html/download
- 2 回答
- 0 關(guān)注
- 236 瀏覽
添加回答
舉報(bào)