Insert multi-line text from a file into another file after the template

I have files like:

text2insert
filewithpattern

and also known:

template

How can I insert rows from text2insertin filewithpattern, but after a row pattern?

Using bash 2.05b

UPDATE: Before filewithpatternshould look like this:

trash
pattern1
pattern2
trash

and after:

garbage
pattern1
text2insert lines
text2insert lines
text2insert lines
pattern2
garbage

+5
source share
2 answers
sed -e '/pattern/r text2insert' filewithpattern
+5
source
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

"" ? , , ""

0

All Articles