插入多行
插入内容中使用\n隔开多行内容
例子:
[root@CHT_centos 74 ~]$cat test.txt
1
2
3
4
5
[root@CHT_centos 75 ~]$sed -i "2a add1: 1\nadd2: 2\n" test.txt
[root@CHT_centos 76 ~]$cat test.txt
1
2
add1: 1
add2: 2
3
4
5
插入一个文本文件内容
[root@CHT_centos 80 ~]$cat test.txt
1
2
3
4
5
[root@CHT_centos 81 ~]$cat test.sh
#!/bin/bash
sed -i "2a add2: 2\nadd3: 3" test.txt
sed -i "4a add4: 4\nadd5: 5" test.txt
[root@CHT_centos 82 ~]$sed -i "2r test.sh" test.txt
[root@CHT_centos 83 ~]$cat test.txt
1
2
#!/bin/bash
sed -i "2a add2: 2\nadd3: 3" test.txt
sed -i "4a add4: 4\nadd5: 5" test.txt
3
4
5
插入前面包含空格的行
[root@CHT_centos 99 ~]$cat test.txt
1
2
3
4
5
[root@CHT_centos 100 ~]$sed -i "2a \ add1" test.txt
[root@CHT_centos 101 ~]$cat test.txt
1
2
add1
3
4
5