文章目录
1. sed 的 追加 a 选项
cat txt aaa 111 bbb ccc 222 ddd eee 333 ggg jjj 444 kkk hhh 555 lll mmm 666 nnn jjj 444 kkk kk 777 ggg
(1). a 追加一行数据
sed -i -e '/jjj 444 kkk/a\test test test' txt cat txt aaa 111 bbb ccc 222 ddd eee 333 ggg jjj 444 kkk test test test #追加 hhh 555 lll mmm 666 nnn jjj 444 kkk test test test #追加 kk 777 ggg
(2). a 追加多行数据
sed -i -e '/jjj 444 kkk/a\one one one\ntwo two two\nthree three three' txt cat txt aaa 111 bbb ccc 222 ddd eee 333 ggg jjj 444 kkk one one one two two two three three three hhh 555 lll mmm 666 nnn jjj 444 kkk one one one two two two three three three kk 777 ggg
注意:
- 不用加 g选项 就默认把符合条件的都加入 a\ 后面的内容
- 加入一行默认是自动换行;最后一行不用加 \n