Insert rows of text into a file after pattern

SHELL=bash
OS=rhel

I have a file1 that contains text in sentences like so:

file1

this is a sentence
this is a sentence
this is a sentence

I also have a file2 like so:

file2

command="
here is some text
here is more text
again we have some text
"

I wish to echo the text from file1 into file2 after the string command="

desired result
file2

command="
this is a sentence
this is a sentence
this is a sentence
here is some text
here is more text
again we have some text
"

Any suggestions would be greatly appreciated.

{ head -n1 file2; cat file1; tail -n+2 file2; }

Sorry I will explain with a bit more detail.

There can be more rows of text above the string command=". So I need to match on the string command=" since this text block can be anywhere in file2. Thanks for your help.

this is another command 
so is this 


command=" here is some text 
here is more text 
again we have some text "

Try:

sed '/^command="/r file1' file2
1 Like

Thank you so much. I modified your first command to use the correct line numbers and it works.

SOLVED