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:
Here were the solutions that worked for me:
Using a marker like explained in another reply:
sed '/StandardMessageTrailer/i MARKER' file1.xml | sed -e '/MARKER/r file2.xml' -e '/MARKER/d'
Counting the line when it occured like explained in another reply to a similar question:
LINE_NUMBER_MATCHING=$(sed -n '/StandardMessageTrailer/=' file1.xml) && sed "$((${LINE_NUMBER_MATCHING} - 1))r file2.xml" file1.xml
Or using sed like explained in another reply to a similar question:
sed $'/StandardMessageTrailer/{e cat file2.xml\n}' file1.xml