test.txt
abcdefga
eeeeeeeaaa
fffffffaa
行首添加的命令如下:
sed 's/^.*aaa/# &/' test.txt
###
### abcdefga
### # eeeeeeeaaa
### fffffffaa
###
在匹配到的行,匹配到的位置前面插入#
注释
行末添加的命令同理:
sed 's/ga/& end/' test.txt
###
### abcdefga end
### eeeeeeeaaa
### fffffffaa
###
备注:思路主要通过关键字配合正则来定位匹配的内容位置,往前面或者后面插入想要的内容