热度 10| ||
https://blog.csdn.net/weixin_34417200/article/details/92202812
感谢大佬!
sed -i -e '/string/{n;d}' -e '$!N;/\n.*string/!P;D' filename
sed -i -e '$!N;/\n.*string/!P;D' filename
sed -i -e '/string/{n;d}' filename
AA=string #变量指定匹配字符串 sed -i -e '/'"$AA"'$/{n;d}' -e '$!N;/\n.*'"$AA"'$/!P;D' file
1 #行前加 2 sed -i '/allow chengyongxu.com/i\allow chengyongxu.cn' the.conf.file 3 #行前后 4 sed -i '/allow chengyongxu.com/a\allow chengyongxu.cn' the.conf.file
sed -i '/listen/a\ listen 80\;' filename
方法①: sed -i '/syncsendmsg.php/a\#013.平台广告小时计划每5分钟写入主平台 xxx 2019-07-04\n*/5 * * * * /usr/bin/php /data/cron/ptask/countjs_syc_plan_main.php\n*/5 * * * * /usr/bin/php /data/cron/ptask/countjs_syc_plan_h_main.php' filename 方法②:匹配字符串,然后在匹配的行的下一行插入多行文本,该文本预先写入某个文件: sed -i '/abcd/r /tmp/otherfile' /var/www/file.conf 这里的/tmp/otherfile是你要添加的文件内容,file.conf就是你要修改的文件
sed -i '/listen/i\ listen 80\;' filename
sed -i -e :a -e '$!N;s/.*\n\(.*ServerName abc.com\)/\1/;ta' -e 'P;D' file 例如: [root@VM_82_178_centos vhost]# grep listen m.afpfpm.cn443.conf listen 80; listen 443; 删除 listen 443;这一行的上行内容: listen 80; sed -i -e :a -e '$!N;s/.*\n\(.*listen 443\)/\1/;ta' -e 'P;D' m.afpfpm.cn443.conf
sed -i '/ServerName abc.com/,/\/VirtualHost/d' $file http://www.linuxso.com/shell/17542.html
sed -i 's/#fastcgi_pass/fastcgi_pass/g;s/fastcgi_pass unix:\/dev\/shm\/php-cgi.sock/#fastcgi_pass unix:\/dev\/shm\/php-cgi.sock/g' m.6saeq.cn443.conf