2 回答

TA貢獻2037條經驗 獲得超6個贊
假設您的輸出存儲在/tmp/output.txt中,請嘗試以下操作:
./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格式,那么您會更輕松。如果您與我們分享您的腳本,我們可能會為您提供進一步幫助。

TA貢獻1890條經驗 獲得超9個贊
這是一個兩步過程:
將列轉置為行,使用冒號作為輸入/輸出分隔符:
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)
}
}
}
用于將點 1 的輸出轉換為 html 表格格式:有一個簡單的腳本可用于執行此操作:https: //sourceforge.net/projects/command-output-to-html-table/可用于轉換任何命令輸出或文件為漂亮的 html 表格格式。您可以為此腳本指定分隔符,包括制表符、換行符等特殊分隔符,并通過頂部的 html 搜索獲取 html 表格格式的輸出。只需下載腳本,解壓并發出以下命令:
cat result.txt | { cat ; echo ; } | ./tabulate.sh -d ":" -t "My Report" -h "My Report" > output.html
這里 : 作為分隔符。
我在這里附加了一個示例output.html:https ://sourceforge.net/projects/my-project-files/files/output.html/download
- 2 回答
- 0 關注
- 255 瀏覽
添加回答
舉報