{"id":1386,"date":"2022-07-19T02:20:29","date_gmt":"2022-07-19T02:20:29","guid":{"rendered":"http:\/\/www.liutianfeng.com\/?p=1386"},"modified":"2022-11-22T05:25:19","modified_gmt":"2022-11-22T05:25:19","slug":"sed%e9%ab%98%e7%ba%a7%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.liutianfeng.com\/?p=1386","title":{"rendered":"sed\u9ad8\u7ea7\u7528\u6cd5"},"content":{"rendered":"<h1>\u8bfe\u9898\u4e00\uff1a\u5220\u9664\u5339\u914d\u884c\u7684\u4e0a\u4e00\u884c\u548c\u4e0b\u4e00\u884c\u6570\u636e<\/h1>\n<h3><strong>1. \u5220\u9664\u5339\u914d\u884c\u7684\u4e0a\u4e00\u884c\u548c\u4e0b\u4e00\u884c\uff1a<\/strong><\/h3>\n<p>sed -i -e &#8216;\/string\/{n;d}&#8217; -e &#8216;$!N;\/\\n.*string\/!P;D&#8217; file.txt<\/p>\n<h3><strong>2. \u5220\u9664\u5339\u914d\u5230\u7279\u5b9a\u5b57\u7b26\u6240\u5728\u884c\u7684\u4e0a\u4e00\u884c<\/strong><\/h3>\n<p>sed -i -e &#8216;$!N;\/\\n.*string\/!P;D&#8217; file.txt<\/p>\n<h3><strong>3. \u5220\u9664\u5339\u914d\u5230\u7279\u5b9a\u5b57\u7b26\u6240\u5728\u884c\u7684\u4e0b\u4e00\u884c<\/strong><\/h3>\n<p>sed -i -e &#8216;\/string\/{n;d}&#8217; file.txt<\/p>\n<h3><strong>4. sed\u4e2d\u4f7f\u7528\u53d8\u91cf\uff0c\u5220\u9664\u5339\u914d\u884c\u7684\u4e0a\u4e00\u884c\u548c\u4e0b\u4e00\u884c\uff1a<\/strong><\/h3>\n<p>AA=string #\u53d8\u91cf\u6307\u5b9a\u5339\u914d\u5b57\u7b26\u4e32<br \/>\nsed -i -e &#8216;\/'&#8221;$AA&#8221;&#8216;$\/{n;d}&#8217; -e &#8216;$!N;\/\\n.*'&#8221;$AA&#8221;&#8216;$\/!P;D&#8217; file.txt<\/p>\n<h3><strong>5. \u5220\u9664\u5339\u914d\u884c\u7684\u540e\u4e24\u884c<\/strong><\/h3>\n<p>sed -n &#8216;\/balabala\/,+2d&#8217; file.txt<\/p>\n<h2>\u8bfe\u9898\u4e8c\uff1a\u5339\u914d\u5230\u5b57\u7b26\u4e32\u6240\u5728\u7684\u884c\u7684\u4e0a\u4e00\u884c\u6216\u8005\u662f\u4e0b\u4e00\u884c\u63d2\u5165\u4e00\u6761\u6570\u636e<\/h2>\n<p>a \u8ffd\u52a0\u5185\u5bb9 sed \u2018\/\u5339\u914d\u8bcd\/a\\\u8981\u52a0\u5165\u7684\u5185\u5bb9\u2019 example.file\uff08\u5c06\u5185\u5bb9\u8ffd\u52a0\u5230\u5339\u914d\u7684\u76ee\u6807\u884c\u7684\u4e0b\u4e00\u884c\u4f4d\u7f6e\uff09<br \/>\ni \u63d2\u5165\u5185\u5bb9 sed \u2018\/\u5339\u914d\u8bcd\/i\\\u8981\u52a0\u5165\u7684\u5185\u5bb9\u2019 example.file \u5c06\u5185\u5bb9\u63d2\u5165\u5230\u5339\u914d\u7684\u884c\u76ee\u6807\u7684\u4e0a\u4e00\u884c\u4f4d\u7f6e\uff09<br \/>\n\u793a\u4f8b\uff1a<br \/>\n#\u6211\u8981\u628a\u6587\u4ef6\u7684\u5305\u542b\u201cchengyongxu.com\u201d\u8fd9\u4e2a\u5173\u952e\u8bcd\u7684\u884c\u524d\u6216\u884c\u540e\u52a0\u5165\u4e00\u884c\uff0c\u5185\u5bb9\u4e3a\u201callow chengyongxu.cn\u201d<\/p>\n<p>1 #\u884c\u524d\u52a0<br \/>\n2 sed -i &#8216;\/allow chengyongxu.com\/i\\allow chengyongxu.cn&#8217; the.conf.file<br \/>\n3 #\u884c\u524d\u540e<br \/>\n4 sed -i &#8216;\/allow chengyongxu.com\/a\\allow chengyongxu.cn&#8217; the.conf.file<br \/>\n\u7ed9\u5339\u914d\u5230\u6587\u4ef6\u4e2d\u5177\u4f53\u7684\u5b57\u7b26\u4e32\u7684\u4e0b\u4e00\u884c\u63d2\u5165\u4e00\u884c\u6570\u636e\uff1a<\/p>\n<p>sed -i &#8216;\/listen\/a\\ listen 80\\;&#8217; filename<br \/>\n\u5728\u5339\u914d\u5230\u7279\u5b9a\u5b57\u7b26\u4e32\u7684\u67d0\u884c\u540e\u6279\u91cf\u63d2\u5165\u591a\u884c\u6570\u636e\uff1a<\/p>\n<p>sed -i &#8216;\/syncsendmsg.php\/a\\#013.\u5e73\u53f0\u5e7f\u544a\u5c0f\u65f6\u8ba1\u5212\u6bcf5\u5206\u949f\u5199\u5165\u4e3b\u5e73\u53f0 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&#8217; filename<br \/>\n\u7ed9\u5339\u914d\u5230\u6587\u4ef6\u4e2d\u5177\u4f53\u7684\u5b57\u7b26\u4e32\u7684\u4e0a\u4e00\u884c\u63d2\u5165\u4e00\u884c\u6570\u636e\uff1a<\/p>\n<p>sed -i &#8216;\/listen\/i\\ listen 80\\;&#8217; filename<\/p>\n<h2>\u8bfe\u9898\u4e09\uff1a\u5220\u9664\u5339\u914d\u5230\u6307\u5b9a\u5b57\u7b26\u4e32\u6240\u5728\u7684\u884c\u7684\u4e0a\u4e00\u884c\u6216\u8005\u662f\u4e0b\u4e00\u884c\u6570\u636e<\/h2>\n<h4><strong>1\u3001\u5220\u9664\u6307\u5b9a\u884c\u7684\u4e0a\u4e00\u884c<\/strong><\/h4>\n<p>sed -i -e :a -e &#8216;$!N;s\/.*\\n\\(.*ServerName abc.com\\)\/\\1\/;ta&#8217; -e &#8216;P;D&#8217; file<br \/>\n\u4f8b\u5982\uff1a<br \/>\n[root@VM_82_178_centos vhost]# grep listen m.afpfpm.cn443.conf<br \/>\nlisten 80;<br \/>\nlisten 443;<\/p>\n<p>\u5220\u9664 listen 443\uff1b\u8fd9\u4e00\u884c\u7684\u4e0a\u884c\u5185\u5bb9\uff1a listen 80;<br \/>\nsed -i -e :a -e &#8216;$!N;s\/.*\\n\\(.*listen 443\\)\/\\1\/;ta&#8217; -e &#8216;P;D&#8217; m.afpfpm.cn443.conf<\/p>\n<h4><strong>2\u3001\u5220\u9664\u6307\u5b9a\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u5185\u5bb9<\/strong><\/h4>\n<p>sed -i &#8216;\/ServerName abc.com\/,\/\\\/VirtualHost\/d&#8217; $file<\/p>\n<p>http:\/\/www.linuxso.com\/shell\/17542.html<br \/>\n\u751f\u4ea7\u4e2dnginx\u914d\u7f6e\u6587\u4ef6\u66ff\u6362\u5b57\u7b26<\/p>\n<p>sed -i &#8216;s\/#fastcgi_pass\/fastcgi_pass\/g;s\/fastcgi_pass unix:\\\/dev\\\/shm\\\/php-cgi.sock\/#fastcgi_pass unix:\\\/dev\\\/shm\\\/php-cgi.sock\/g&#8217; m.6saeq.cn443.conf<br \/>\n\u4eca\u5929\u6f14\u793a\u5230\u6b64\u5904\uff0c\u6b22\u8fce\u7559\u8a00\u4e00\u8d77\u4ea4\u6d41\u5b66\u4e60<\/p>\n<p>\u5904\u7406\u6362\u884c\uff1ahttps:\/\/blog.csdn.net\/dualvencsdn\/article\/details\/120721476<\/p>\n<p><strong>\u4e60\u9898\uff1a<\/strong><\/p>\n<p>https:\/\/blog.csdn.net\/woshibianhe\/article\/details\/7295789<\/p>\n<p>\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1a<a href=\"https:\/\/www.liutianfeng.com\">liutianfeng.com<\/a> &raquo; <a href=\"https:\/\/www.liutianfeng.com\/?p=1386\">sed\u9ad8\u7ea7\u7528\u6cd5<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u8bfe\u9898\u4e00\uff1a\u5220\u9664\u5339\u914d\u884c\u7684\u4e0a\u4e00\u884c\u548c\u4e0b\u4e00\u884c\u6570\u636e 1. \u5220\u9664\u5339\u914d\u884c\u7684\u4e0a\u4e00\u884c\u548c\u4e0b\u4e00\u884c\uff1a sed -i -e &#8216; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[57],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1386"}],"collection":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1386"}],"version-history":[{"count":10,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1386\/revisions"}],"predecessor-version":[{"id":1513,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=\/wp\/v2\/posts\/1386\/revisions\/1513"}],"wp:attachment":[{"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liutianfeng.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}