Sed在匹配行前后加入一行

a 追加内容 sed ‘/匹配词/a\要加入的内容’ example.file(将内容追加到匹配的目标行的下一行位置)
i 插入内容 sed ‘/匹配词/i\要加入的内容’ example.file 将内容插入到匹配的行目标的上一行位置)
示例:
#我要把文件的包含“chengyongxu.com”这个关键词的行前或行后加入一行,内容为“allow chengyongxu.cn”

1#行前加
2sed -i '/allow chengyongxu.com/i\allow chengyongxu.cn' the.conf.file
3#行前后
4sed -i '/allow chengyongxu.com/a\allow chengyongxu.cn' the.conf.file

Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 169

Notice: Only variables should be assigned by reference in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/item.php on line 478
back to top