How can I can insert the contents of a file into another file right before a specific line
- by jelbatnigi
Hi,
How can I can insert the contents of a file into another file right before a specific line using sed.
example I have file1.xml that has the following:
<field tagRef="376">
</field>
<field tagRef="377">
</field>
<field tagRef="58">
</field>
<group ref="StandardMessageTrailer" required="true"/>
</fieldList>
and file2.xml has the following:
<field tagRef="9647">
<description>Offset</description>
</field>
<field tagRef="9648">
<description>Offset Units/Direction</description>
</field>
<field tagRef="9646">
<description>Anchor Price</description>
</field>
how can i insert the contents of file2 into file1 just before
so it will look like this:
<field tagRef="376">
</field>
<field tagRef="377">
</field>
<field tagRef="58">
</field>
<field tagRef="9647">
<description>Offset</description>
</field>
<field tagRef="9648">
<description>Offset Units/Direction</description>
</field>
<field tagRef="9646">
<description>Anchor Price</description>
</field>
<group ref="StandardMessageTrailer" required="true"/>
</fieldList>
I know how to insert after that line using
sed 'group ref="StandardMessageTrailer"/r file2.xml' file1.xml newfile.xml
but I want to insert it before.
appreciate the help