![我需要使用 shell 脚本在两个模式之间插入一个大字符串](https://linux22.com/image/1160367/%E6%88%91%E9%9C%80%E8%A6%81%E4%BD%BF%E7%94%A8%20shell%20%E8%84%9A%E6%9C%AC%E5%9C%A8%E4%B8%A4%E4%B8%AA%E6%A8%A1%E5%BC%8F%E4%B9%8B%E9%97%B4%E6%8F%92%E5%85%A5%E4%B8%80%E4%B8%AA%E5%A4%A7%E5%AD%97%E7%AC%A6%E4%B8%B2.png)
我有一个 HTML 文件,其中有一行注释如下:
<!-- tag1 --><!-- tag11 -->
我需要JQ
在它们之间插入一个文件元素。
我试过,可以插入小字符串,但我的字符串很大。有人能给我一个建议吗?
i=0
code="(jq -r '.["$i"].code' file.json)";
eval v=\$$code;
sed -i 's/(<!-- tag1 -->)\(<!-- tag11 -->)/\1'$v'\2/' index.html;
它向我抛出了一个错误:
sed: -e expression #1, char 47: unterminated `s' command
然而:
v="xxxxxxx"
sed -i 's/(<!-- tag1 -->)\(<!-- tag11 -->)/\1'$v'\2/' index.html;
字符串已完美插入,有人可以帮忙吗?