printf '%s\n' /PAT/s/PAT/\&\\ \/ - kb ". r insert.txt" j \'b j ,p q | ed -s file.txt
printf '%s\n' /PAT/s/PAT/\&\\ \/ - kb ". r insert.txt" j \'b j w q | ed -s file.txt
/PAT/s/PAT/&\ # set address to first line matching PAT and
/ # split the line right after PAT
- # set address one line before (return to the line matching PAT)
kb # mark the current line
. r insert.txt # insert content of insert.txt after this line
j # join current line and the next
'b # set address to marked line (return to the line matching PAT)
j # join current line and the next one
,p # print file content
q # quit editor
Or, without using printf and |:
ed -s file.txt <<< $'/PAT/s/PAT/&\\\n/\n-\nkb\n. r insert.txt\nj\n\'b\nj\nw\nq\n'