将多行文本从文件插入到另一个文件之后。

时间:2021-10-19 20:07:45

I have files like:

我有文件:

text2insert
filewithpattern

text2insert filewithpattern

and also known:

又称:

pattern

模式

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

如何将text2insert的行插入到filewithpattern中,但是在模式行之后?

Using bash 2.05b

使用bash 2.05 b

UPDATE: Before filewithpattern should look like:

更新:在filewithpattern之前应该是:

garbage
pattern1
pattern2
garbage

垃圾pattern1 pattern2垃圾

and after:

后:

garbage
pattern1
text2insert lines
text2insert lines
text2insert lines
pattern2
garbage

,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

2 个解决方案

#1


5  

sed -e '/pattern/r text2insert' filewithpattern

#2


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"

为什么在输出中需要“垃圾”呢?你之前的问题似乎不包括“垃圾”

#1


5  

sed -e '/pattern/r text2insert' filewithpattern

#2


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"

为什么在输出中需要“垃圾”呢?你之前的问题似乎不包括“垃圾”

相关文章