【问题标题】:convert a text file output to a html format using bash使用 bash 将文本文件输出转换为 html 格式
【发布时间】:2014-03-09 17:19:11
【问题描述】:

您好我正在尝试将文本文件转换为带有表格的 html,以便我可以以表格格式邮寄输出,我使用了awk 'BEGIN{print "Content-Type: text/html; charset="us-ascii""\n "<html>"\n "<Body>"\n "<table>"} {print "<tr>";for(i=1;i<=NF;i++)print "<td>" $i"</td>";print "</tr>"} END{print \n</Body>"\n "</html>"\n"</table>"}' a.txt >> email.html,但我遇到了问题,有人可以帮我解决这个问题

【问题讨论】:

    标签: bash awk


    【解决方案1】:

    -Edited- 它适用于:

    awk '
    BEGIN{
        print "Content-Type: text/html; charset="us-ascii"\n<html>\n<head>\n<style>\ntable                 ,   th,td\n{\n border:1px solid black;
        border-collapse:collapse;\n}\n</style>\n</head>\n<Body>\n<table>"
        } 
        {print "<tr>"
        for(i=1;i<=NF;i++)
            print "<td>" $i"</td>"
        print "</tr>"
        }
        END{
        print "\n</table>\n</Body>\n</html>\n" 
        }' a.txt >> email.html
    

    【讨论】:

      【解决方案2】:

      您需要清洁您的生产线。 \n 需要像这样用双引号括起来:

      awk '
      BEGIN{
          print "Content-Type: text/html; charset=us-ascii\n <html>\n <Body>\n<table>"
          } 
          {print "<tr>"
          for(i=1;i<=NF;i++)
              print "<td>" $i"</td>"
          print "</tr>"
          }
      END{
          print "\n</Body>\n</html>\n</table>"
          }' a.txt >> email.html
      

      【讨论】:

      • 酷 .. 但cat email.html | sendmail -t tmp@exmple.com 不起作用我无法通过表格接收输出
      猜你喜欢
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 2017-03-30
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 2013-11-11
      • 1970-01-01
      相关资源
      最近更新 更多