5

I have files like:

text2insert
filewithpattern

and also known:

pattern

How can i insert lines from text2insert into filewithpattern but after the pattern line?

Using bash 2.05b

UPDATE: Before filewithpattern should look like:

garbage
pattern1
pattern2
garbage

and after:

garbage
pattern1
text2insert lines
text2insert lines
text2insert lines
pattern2
garbage

kasper
  • 611
  • 2
  • 8
  • 18

2 Answers2

5
sed -e '/pattern/r text2insert' filewithpattern
Dennis Williamson
  • 324,833
  • 88
  • 366
  • 429
0
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"

kurumi
  • 24,217
  • 4
  • 43
  • 49