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>
</message>
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
<group ref="StandardMessageTrailer" required="true"/>
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>
</message>
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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…