sed实例(持续更新)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sed实例(持续更新)相关的知识,希望对你有一定的参考价值。

1、在最后一行加:

sed -i '$a\Defaults logfile=/var/log/sudo.log' /etc/sudoers


2、替换字符:

sed -i 's/Allow from .example.com/Allow from localhost/g' /usr/local/xxx/config/apache/extra/httpd-info.conf


3、在匹配行下方几行开始加:

sed -i -e '/location ~ \/\\.ht/{n;n;s|$|\n #-------------------------------------------------|}' /usr/local/xxx/config/nginx/vhost/default.conf

sed -i -e '/location ~ \/\\.ht/{n;n;n;s|$|\n location /nginx-status {|}' /usr/local/xxx/config/nginx/vhost/default.conf

sed -i -e '/location ~ \/\\.ht/{n;n;n;n;s|$|\n stub_status on;|}' /usr/local/xxx/config/nginx/vhost/default.conf

sed -i -e '/location ~ \/\\.ht/{n;n;n;n;n;s|$|\n access_log off;|}' /usr/local/xxx/config/nginx/vhost/default.conf

sed -i -e '/location ~ \/\\.ht/{n;n;n;n;n;n;s|$|\n }|}' /usr/local/xxx/config/nginx/vhost/default.conf


4、删除匹配性开头的行:

sed -i '/^Defaults logfile=\/var\/log\/sudo.log.*/d' /etc/sudoers


5、删除匹配行,并且删除前一行,后三行:

sed -i '/location \/nginx-status/,+3d;:go;1,1!{P;$!N;D};N;bgo' /usr/local/u-mail/config/nginx/vhost/default.conf


以上是关于sed实例(持续更新)的主要内容,如果未能解决你的问题,请参考以下文章

持续更新—Nginx日志分析方法

python实例(持续更新)

文本里常用的替换(持续更新.......)

亿邦动力抓取实例,持续更新

Zabbix遇到的问题——持续更新

msyql命令实例(持续更新)