10.3.5 插入文本
使用i或a命令插入文本,其中i代表在匹配行之前插入,而a代表在匹配行之后插入,示例如下:
#
使用i
在第二行前插入文本
[root@localhost ~]# sed '2 i Insert' Sed.txt this is line 1, this is First line Insert
this is line 2, the Second line, Empty line followed this is line 4, this is Third line this is line 5, this is Fifth line #
使用a
在第二行后插入文本
[root@localhost ~]# sed '2 a Insert' Sed.txt this is line 1, this is First line this is line 2, the Second line, Empty line followed Insert
this is line 4, this is Third line this is line 5, this is Fifth line #
在匹配行的上一行插入问题
[root@localhost ~]# sed 'Secondi\Insert' Sed.txt this is line 1, this is First line Insert
this is line 2, the Second line, Empty line followed this is line 4, this is Third line this is line 5, this is Fifth line