sed命令
在匹配行的前后插入新行,sed的man手册说明如下:
a \行后
text Append text, which has each embedded newline preceded by a backslash.
i \行前
text Insert text, which has each embedded newline preceded by a backslash.
示例如下:
行后插入内容:
sed -i "/This is the test line/a\This is the line we inserted." /root/test.txt
行前插入内容:
sed -i "/This is the test line/i\This is the line we inserted." /root/test.txt