sed 一次性插入多行

有時候須要利用 sed 來修改設定檔
原本的檔案,要在 1 和 4 之間插入 2 & 3
# cat /root/testfile
1
4
5
6
7[@more@]# sed -i ‘/1/a2n3’ /root/testfile

# sed -i ‘/4/i2n3’ /root/testfile

處理完後
# cat /root/testfile
1
2
3
4
5
6
7

另外的一行方式
參考網頁:sed在匹配行之下追加多行文本 – 陆小K网络工作室 – 51CTO技术博客
找到 7 後,在下方插入 /root/nginx.conf 內容
# sed -i ‘/7/r /root/nginx.conf’ /root/testfile