【问题标题】:How to insert csv file content into html file within pre tag using shell script如何使用 shell 脚本将 csv 文件内容插入到 pre 标记内的 html 文件中
【发布时间】:2021-07-05 16:46:22
【问题描述】:

我需要插入csv文件(file.csv)内容如:

col1, col2, ...coln
1,2,3
4,5,6
.
.
100,101,102

放入<pre> </pre>标签内的html文件(file.html)。

file.html中的愿望结果:

<html>
.
.
<pre>
col1, col2, ...coln
1,2,3
4,5,6
.
.
100,101,102
</pre>
.
.
</html>

我知道它可以使用sed 完成,但不知道具体细节。
谢谢。

【问题讨论】:

  • 你的结果是你想要的实际结果吗?还是只是一个sn-p?到底有没有一个&lt;pre&gt;
  • @NickSlash 它只是一个 sn-p,在这种情况下只有一个
  • 请提供格式正确的示例 HTML 输入文件。
  • 不过,最好的办法是使用一些支持 HTML 的预处理器、静态页面生成器或服务器内模板引擎。

标签: html shell csv


【解决方案1】:

这行得通:

gawk -i inplace '/<pre[^>]*>/{printf $0; while(getline line<"file.csv"){print line};next}1' file.html &&

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 2013-09-06
    • 2013-04-27
    • 2011-07-04
    • 2019-12-20
    相关资源
    最近更新 更多