I recently asked a similar question How To Insert File Contents After Line Match While Escaping Backslash only to realize I need to do the opposite.
Using the code from that question, I have tried:
sed '/<\\tag>/i file2' file1
2nd attempt:
awk '/<\\tag>/{print;system("cat File2.txt");before} 1' File1.txt
However, I'm unable to get it to insert one line before the match.
Example:
File1.txt
Hello <[World!]> 1
Hello <[World!]> 2
File2.txt:
<thanks>
<tag>
<example>
<new>
<\new>
<\example>
<\tag>
<\thanks>
Desired output:
<thanks>
<tag>
<example>
<new>
<\new>
<\example>
Hello <[World!]> 1
Hello <[World!]> 2
<\tag>
<\thanks>
If you could please help me insert the file contents after a line match while escaping a backslash, I would really appreciate it.