sed实例(持续更新)
生活随笔
收集整理的這篇文章主要介紹了
sed实例(持续更新)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、在最后一行加:
sed?-i?'$a\Defaults?logfile=/var/log/sudo.log'?/etc/sudoers2、替換字符:
sed?-i?'s/Allow?from?.example.com/Allow?from?localhost/g'?/usr/local/xxx/config/apache/extra/httpd-info.conf3、在匹配行下方幾行開始加:
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.conf4、刪除匹配性開頭的行:
sed?-i?'/^Defaults?logfile=\/var\/log\/sudo.log.*/d'?/etc/sudoers5、刪除匹配行,并且刪除前一行,后三行:
sed?-i?'/location?\/nginx-status/,+3d;:go;1,1!{P;$!N;D};N;bgo'?/usr/local/xxx/config/nginx/vhost/default.conf6、利用字符串匹配取區間
7、從多少行到多少行
sed?-n?'16214,24400p'?default.err?>mysqlerr.log8、將\n換行符替換成空格(sed高級應用很重要)
[root@localhost?~]#?chkconfig?--list?|?grep?xyz|?awk?'{print?$1}'?|?sed?'s/\/n/?/g' xyz_apache xyz_app xyz_clamd xyz_ctasd_in xyz_ctasd_out xyz_dovecot xyz_dspam xyz_mysqld xyz_nginx xyz_openldap xyz_postfix xyz_postgresql xyz_postgrey xyz_redis xyz_spamassassin方法1: [root@localhost?~]#?chkconfig?--list?|?grep?umail|?awk?'{print?$1}'?|?sed?':a;N;s/\n/?/g;ta' xyz_apache?xyz_app?xyz_clamd?xyz_ctasd_in?xyz_ctasd_out?xyz_dovecot?xyz_dspam?xyz_mysqld?xyz_nginx?xyz_openldap?xyz_postfix?xyz_postgresql?xyz_postgrey?xyz_redis?xyz_spamassassin方法2: [root@localhost?~]#?chkconfig?--list?|?grep?umail|?awk?'{print?$1}'?|?tr?"\n"?"?" xyz_apache?xyz_app?xyz_clamd?xyz_ctasd_in?xyz_ctasd_out?xyz_dovecot?xyz_dspam?xyz_mysqld?xyz_nginx?xyz_openldap?xyz_postfix?xyz_postgresql?xyz_postgrey?xyz_redis?xyz_spamassassin命令擴展: [root@localhost~]#?for?i?in?`chkconfig?--list?|?grep?xyz|?awk?'{print?$1}'?|?sed?':a;N;s/\n/?/g;ta'`;?do?/etc/init.d/$i?status;?done9、刪除空行
sed?'/^$/d'轉載于:https://blog.51cto.com/net881004/2053962
總結
以上是生活随笔為你收集整理的sed实例(持续更新)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【python】-- pymsql 外键
- 下一篇: redis desktop manage