bash 如何以表格格式邮寄脚本输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34573527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:04:30 来源:igfitidea点击:
how to mail script output in table format
提问by Thej
I have the script output like below.
我有如下所示的脚本输出。
Current result:
当前结果:
Filename Destname rowcount bytesize
file1 default 1488 2248
file2 default 123 657
file3 default 123 456
file4 default 567 124
Actual result to be like below (if possible with borders):
实际结果如下(如果可能有边框):
Filename Destname rowcount bytesize
file1 default 1488 2248
file2 default 123 657
file3 default 123 456
file4 default 567 124
I need to mail above content in same format.
我需要以相同的格式邮寄上述内容。
回答by Cyrus
#!/bin/bash
input="/path/to/your/file.txt"
tmpfile="/path/to/tmpfile.html"
echo 'Content-Type: text/html; charset="us-ascii" ' > "$tmpfile"
awk 'BEGIN{print "<html><body><table border=1>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print "</table></body></html>"}' "$input" >> "$tmpfile"
mail -s "test" [email protected] < "$tmpfile"