开发者

Inserting multiline text from file to another file after pattern

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

garba开发者_StackOverflow社区ge

and after:

garbage

pattern1

text2insert lines

text2insert lines

text2insert lines

pattern2

garbage


sed -e '/pattern/r text2insert' filewithpattern


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜