I have files like:
text2insert filewithpattern
and also known:
pattern
How
awk 'FNR==NR{ a[c++]=$0;next } /pattern1/{g=1;next} /pattern2/{g=0;next} g{ for(i=1;i<=c;i++){ print a[i] } }' text2insert filewithpattern
And why do you need "garbage" in your output? Your previous question seems not to include "garbage"
sed -e '/pattern/r text2insert' filewithpattern