问题描述
我正在尝试使用在这里找到的代码:在特定模式匹配后插入文件内容
I'm trying to use code that I found here: Insert contents of a file after specific pattern match
但是,当我在代码中添加反斜杠时,它不起作用.因此,然后,我按照此处的说明进行操作:在sed中使用斜杠和反斜杠更改sed
中的定界符.但是,当我这样做时,插入内容(应该是几行)变成数千个.
However, when I add a backslash to the code, it doesn't work. So, then, I followed the instructions here: Slash and backslash in sed to change the delimiters in sed
. However, when I do that, the insert (which should be a few lines), turns into thousands.
这是我的尝试:
sed ':<\tag>: r file1.txt' file2.txt
示例:
File1.txt
File1.txt
Hello World 1
Hello World 2
File2.txt:
File2.txt:
<thanks>
<tag>
<example>
<new>
<\new>
<\example>
<\tag>
<\thanks>
所需的输出:
<thanks>
<tag>
<example>
<new>
<\new>
<\example>
<\tag>
Hello World 1
Hello World 2
<\thanks>
如果您可以帮助我在转义后插入文件内容,同时转义反斜杠,我将不胜感激.
If you could please help me insert the file contents after a line match while escaping a backslash, I would really appreciate it.
推荐答案
尝试一下
sed '/<\\tag>/r file2' file1
我认为您交换了file1和file2.
I think you swapped file1 and file2.
这篇关于如何在转义符后转义反斜杠时插入文件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!