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
  • 641
  • 2
  • 8
  • 18

2 Answers2

5
sed -e '/pattern/r text2insert' filewithpattern
Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
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
  • 25,121
  • 5
  • 44
  • 52