我正在尝试使用我在这里找到的代码:在特定模式匹配后插入文件内容 https://stackoverflow.com/questions/16715373/insert-contents-of-a-file-after-specific-pattern-match
但是,当我在代码中添加反斜杠时,它不起作用。因此,我按照此处的说明进行操作:sed 中的斜杠和反斜杠 https://unix.stackexchange.com/questions/211834/slash-and-backslash-in-sed更改分隔符sed
。然而,当我这样做时,插入(应该是几行)变成了数千行。
这是我的尝试:
sed ':<\tag>: r file1.txt' file2.txt
Example:
文件1.txt
Hello World 1
Hello World 2
文件2.txt:
<thanks>
<tag>
<example>
<new>
<\new>
<\example>
<\tag>
<\thanks>
期望的输出:
<thanks>
<tag>
<example>
<new>
<\new>
<\example>
<\tag>
Hello World 1
Hello World 2
<\thanks>
如果您能帮助我在行匹配后插入文件内容,同时转义反斜杠,我将非常感激。
try this
sed '/<\\tag>/r file2' file1
我认为您交换了 file1 和 file2。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)