{"id":61246,"date":"2025-04-29T09:34:41","date_gmt":"2025-04-29T01:34:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/61246\/"},"modified":"2025-04-29T09:34:41","modified_gmt":"2025-04-29T01:34:41","slug":"%e6%8e%8c%e6%8f%a1-linux-sed-%e5%91%bd%e4%bb%a4%e7%bb%bc%e5%90%88%e6%8c%87%e5%8d%97-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/61246\/","title":{"rendered":"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357"},"content":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3a\u521d\u5b66\u8005\u63d0\u4f9b\u4e86\u5173\u4e8e  \u4e2d sed \u547d\u4ee4\u7684\u5168\u9762\u6307\u5357\uff0c\u6db5\u76d6\u4e86\u5176\u5386\u53f2\u3001\u7528\u9014\u4ee5\u53ca\u4e00\u4e9b\u5b9e\u7528\u7684\u6280\u5de7\u548c\u7a8d\u95e8\u3002\u4e86\u89e3 sed \u5e76\u719f\u7ec3\u8fd0\u7528\uff0c\u80fd\u591f\u9ad8\u6548\u5730\u5904\u7406\u6587\u672c\uff0c\u8fd9\u662f\u5728 linux \u4e0b\u7684\u4efb\u4f55\u7528\u6237\u90fd\u5e94\u8be5\u5177\u5907\u7684\u5b9d\u8d35\u6280\u80fd\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/168842918810000.jpg\" class=\"aligncenter\" title=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe\" alt=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe\" \/><\/p>\n<h4>\u8bf4\u660e<\/h4>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u7684\u76ee\u7684\u662f\u4e3a\u521d\u5b66\u8005\u63d0\u4f9b\u5173\u4e8e\u5982\u4f55\u5168\u9762\u4f7f\u7528\u6d41\u7f16\u8f91\u5668 sed \u547d\u4ee4\u5728 Linux \u4e2d\u7684\u6307\u5357\u3002\u5b83\u6db5\u76d6\u4e86\u8be5\u547d\u4ee4\u7684\u5386\u53f2\u3001\u7528\u6cd5\u3001\u53c2\u6570\u3001\u5e38\u89c1\u7528\u4f8b\u4ee5\u53ca\u6280\u5de7\u548c\u7a8d\u95e8\u3002<\/p>\n<h4>\u5386\u53f2<\/h4>\n<p>\u81eaUNIX\u7684\u65e9\u671f\u5f00\u53d1\u4ee5\u6765\uff0csed\u547d\u4ee4\u4fbf\u6210\u4e3aLinux\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e00\u76f4\u6cbf\u7528\u81f3\u4eca\u3002\u5b83\u88ab\u5e7f\u6cdb\u7528\u4e8e\u6587\u672c\u5904\u7406\uff0c\u5e76\u4ee5\u5176\u9ad8\u6548\u548c\u5feb\u901f\u800c\u95fb\u540d\u3002<\/p>\n<h4>\u4f55\u65f6\u4ee5\u53ca\u4e3a\u4ec0\u4e48\u4f7f\u7528\u5b83<\/h4>\n<p>\u5f53\u60a8\u9700\u8981\u5728\u6587\u4ef6\u6216\u6d41\u4e0a\u9ad8\u6548\u5730\u6267\u884c\u6587\u672c\u8f6c\u6362\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 sed\u3002\u5b83\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u80fd\u591f\u5904\u7406\u5927\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6a21\u5f0f\u5339\u914d\u548c\u66ff\u6362\uff0c\u8fd9\u4f7f\u5176\u6210\u4e3a\u811a\u672c\u7f16\u5199\u548c\u6570\u636e\u6574\u7406\u7684\u5fc5\u5907\u5de5\u5177\u3002<\/p>\n<h4>\u5982\u4f55\u4f7f\u7528\u5b83<\/h4>\n<p>sed \u547d\u4ee4\u7684\u57fa\u672c\u8bed\u6cd5\u662f sed \u2018command\u2019 file_name\u3002<\/p>\n<pre>linuxmi@linuxmi ~\/www.linuxmi.com % echo \"Hello World\" | sed 's\/World\/linux\u8ff7www.linuxmi.com\/'Hello linux\u8ff7www.linuxmi.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/168842918914154.png\" class=\"aligncenter\" title=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe1\" alt=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe1\" \/><\/p>\n<h4>\u5e38\u7528\u53c2\u6570<\/h4>\n<p>-n\uff1a\u7981\u6b62\u81ea\u52a8\u6253\u5370\u6a21\u5f0f\u7f13\u51b2\u533a\u3002<\/p>\n<pre>linuxmi@linuxmi ~\/www.linuxmi.com % echo \"Hello World\" | sed -n 's\/World\/linux\u8ff7www.linuxmi.com\/p'Hello linux\u8ff7www.linuxmi.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/168842918970642.png\" class=\"aligncenter\" title=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe2\" alt=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe2\" \/><\/p>\n<p>\u4f7f\u7528-i\u53c2\u6570\uff0csed\u547d\u4ee4\u4f1a\u76f4\u63a5\u4fee\u6539\u6e90\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u5c06\u4fee\u6539\u7ed3\u679c\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\u3002\u4e3a\u4e86\u9632\u6b62\u6570\u636e\u4e22\u5931\uff0c\u5f53\u7ed9\u5b9a\u6269\u5c55\u540d\u65f6\uff0csed\u5728\u8fdb\u884c\u6587\u4ef6\u7f16\u8f91\u4e4b\u524d\u4f1a\u521b\u5efa\u4e00\u4e2a\u5907\u4efd\u6587\u4ef6\u3002<\/p>\n<pre>linuxmi@linuxmi ~\/www.linuxmi.com % echo \"Hello World\" &amp;gt; linuxmi.txtlinuxmi@linuxmi ~\/www.linuxmi.com % sed -i 's\/World\/Linux\u8ff7www.linuxmi.com\/' linuxmi.txtlinuxmi@linuxmi ~\/www.linuxmi.com % cat linuxmi.txtHello Linux\u8ff7www.linuxmi.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/168842918940041.png\" class=\"aligncenter\" title=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe3\" alt=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe3\" \/><\/p>\n<h4>\u5176\u4ed6\u652f\u6301\u7684\u53c2\u6570<\/h4>\n<ul>\n<li>-e\uff1a\u5141\u8bb8\u4f7f\u7528\u591a\u4e2a\u7f16\u8f91\u547d\u4ee4\u3002<\/li>\n<li>-f\uff1a\u5141\u8bb8\u6307\u5b9a\u5305\u542bsed\u547d\u4ee4\u7684\u6587\u4ef6\u3002<\/li>\n<li>-r\uff1a\u4f7f\u7528\u6269\u5c55\u6b63\u5219\u8868\u8fbe\u5f0f\u3002<\/li>\n<li>-u\uff1a\u4f7f\u7f13\u51b2\u533a\u65e0\u7f13\u51b2\u3002<\/li>\n<\/ul>\n<h4>\u6700\u5e38\u89c1\u7684\u7528\u4f8b<\/h4>\n<p>sed \u7684\u5e38\u89c1\u7528\u4f8b\u4e4b\u4e00\u662f\u5728\u6587\u4ef6\u4e2d\u66ff\u6362\u6587\u672c\u3002<\/p>\n<pre>linuxmi@linuxmi ~\/www.linuxmi.com % echo \"Hello World! www.linuxmi.com\" &amp;gt; linuxmi.txtlinuxmi@linuxmi ~\/www.linuxmi.com % sed -i 's\/World\/linuxmi.com\/' linuxmi.txtlinuxmi@linuxmi ~\/www.linuxmi.com % cat linuxmi.txtHello linuxmi.com! www.linuxmi.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/168842918974692.png\" class=\"aligncenter\" title=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe4\" alt=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe4\" \/><\/p>\n<h4>\u6280\u5de7<\/h4>\n<p>sed\u53ef\u4ee5\u901a\u8fc7\u94fe\u5f0f\u591a\u4e2a\u547d\u4ee4\u5728\u4e00\u884c\u547d\u4ee4\u4e2d\u6267\u884c\u590d\u6742\u7684\u6587\u672c\u8f6c\u6362\u3002<\/p>\n<pre>linuxmi@linuxmi ~\/www.linuxmi.com % echo \"Hello World\" | sed 's\/Hello\/Hi\/; s\/World\/Linux\u8ff7www.linuxmi.com\/'Hi Linux\u8ff7www.linuxmi.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/168842918949389.png\" class=\"aligncenter\" title=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe5\" alt=\"\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u63d2\u56fe5\" \/><\/p>\n<h4>\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9879<\/h4>\n<p>\u5f53\u4f7f\u7528-i\u9009\u9879\u65f6\uff0c\u8981\u6ce8\u610f\u5b83\u53ef\u80fd\u5bf9\u6587\u4ef6\u8fdb\u884c\u4e0d\u53ef\u9006\u7684\u4fee\u6539\u3002\u5728\u5904\u7406\u91cd\u8981\u6570\u636e\u65f6\uff0c\u52a1\u5fc5\u786e\u4fdd\u8fdb\u884c\u5907\u4efd\u3002<\/p>\n<h4>\u603b\u7ed3<\/h4>\n<p>sed\u662f\u547d\u4ee4\u884c\u6587\u672c\u5904\u7406\u7684\u5f3a\u5927\u5de5\u5177\u3002\u501f\u52a9\u5b83\uff0c\u60a8\u53ef\u4ee5\u9ad8\u6548\u6709\u6548\u5730\u8fdb\u884c\u590d\u6742\u7684\u6587\u672c\u8f6c\u6362\u3002\u719f\u7ec3\u638c\u63e1sed\u5c06\u63d0\u9ad8\u60a8\u5728\u6587\u672c\u5904\u7406\u4efb\u52a1\u4e2d\u7684\u751f\u4ea7\u529b\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u638c\u63e1 Linux sed \u547d\u4ee4\u7efc\u5408\u6307\u5357\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u4e3a\u521d\u5b66\u8005\u63d0\u4f9b\u4e86\u5173\u4e8e \u4e2d sed \u547d\u4ee4\u7684\u5168\u9762\u6307\u5357\uff0c\u6db5\u76d6\u4e86\u5176\u5386\u53f2\u3001\u7528\u9014\u4ee5\u53ca\u4e00\u4e9b\u5b9e\u7528\u7684\u6280\u5de7\u548c\u7a8d\u95e8\u3002\u4e86\u89e3 sed \u5e76\u719f\u7ec3\u8fd0\u7528\uff0c\u80fd\u591f\u9ad8\u6548\u5730\u5904\u7406\u6587\u672c\uff0c\u8fd9\u662f\u5728 linux \u4e0b\u7684\u4efb\u4f55\u7528\u6237\u90fd\u5e94\u8be5\u5177\u5907\u7684\u5b9d\u8d35\u6280\u80fd\u3002 \u8bf4\u660e \u8fd9\u7bc7\u6587\u7ae0\u7684\u76ee\u7684\u662f\u4e3a\u521d\u5b66\u8005\u63d0\u4f9b\u5173\u4e8e\u5982\u4f55\u5168\u9762\u4f7f\u7528\u6d41\u7f16\u8f91\u5668 sed \u547d\u4ee4\u5728 Linux \u4e2d\u7684\u6307\u5357\u3002\u5b83\u6db5\u76d6\u4e86\u8be5\u547d\u4ee4\u7684\u5386\u53f2\u3001\u7528\u6cd5\u3001\u53c2\u6570\u3001\u5e38\u89c1\u7528\u4f8b\u4ee5\u53ca\u6280\u5de7\u548c\u7a8d\u95e8\u3002 \u5386\u53f2 \u81eaUNIX\u7684\u65e9\u671f\u5f00\u53d1\u4ee5\u6765\uff0csed\u547d\u4ee4\u4fbf\u6210\u4e3aLinux\u7684\u4e00\u90e8\u5206\uff0c\u5e76\u4e00\u76f4\u6cbf\u7528\u81f3\u4eca\u3002\u5b83\u88ab\u5e7f\u6cdb\u7528\u4e8e\u6587\u672c\u5904\u7406\uff0c\u5e76\u4ee5\u5176\u9ad8\u6548\u548c\u5feb\u901f\u800c\u95fb\u540d\u3002 \u4f55\u65f6\u4ee5\u53ca\u4e3a\u4ec0\u4e48\u4f7f\u7528\u5b83 \u5f53\u60a8\u9700\u8981\u5728\u6587\u4ef6\u6216\u6d41\u4e0a\u9ad8\u6548\u5730\u6267\u884c\u6587\u672c\u8f6c\u6362\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 sed\u3002\u5b83\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u80fd\u591f\u5904\u7406\u5927\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u8fdb\u884c\u6a21\u5f0f\u5339\u914d\u548c\u66ff\u6362\uff0c\u8fd9\u4f7f\u5176\u6210\u4e3a\u811a\u672c\u7f16\u5199\u548c\u6570\u636e\u6574\u7406\u7684\u5fc5\u5907\u5de5\u5177\u3002 \u5982\u4f55\u4f7f\u7528\u5b83 sed \u547d\u4ee4\u7684\u57fa\u672c\u8bed\u6cd5\u662f sed \u2018command\u2019 file_name\u3002 linuxmi@linuxmi ~\/www.linuxmi.com % echo &#8220;Hello World&#8221; | sed &#8216;s\/World\/linux\u8ff7www.linuxmi.com\/&#8217;Hello linux\u8ff7www.linuxmi.com \u767b\u5f55\u540e\u590d\u5236 \u5e38\u7528\u53c2\u6570 -n\uff1a\u7981\u6b62\u81ea\u52a8\u6253\u5370\u6a21\u5f0f\u7f13\u51b2\u533a\u3002 linuxmi@linuxmi ~\/www.linuxmi.com % echo &#8220;Hello World&#8221; | sed -n &#8216;s\/World\/linux\u8ff7www.linuxmi.com\/p&#8217;Hello linux\u8ff7www.linuxmi.com \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528-i\u53c2\u6570\uff0csed\u547d\u4ee4\u4f1a\u76f4\u63a5\u4fee\u6539\u6e90\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u5c06\u4fee\u6539\u7ed3\u679c\u8f93\u51fa\u5230\u6807\u51c6\u8f93\u51fa\u3002\u4e3a\u4e86\u9632\u6b62\u6570\u636e\u4e22\u5931\uff0c\u5f53\u7ed9\u5b9a\u6269\u5c55\u540d\u65f6\uff0csed\u5728\u8fdb\u884c\u6587\u4ef6\u7f16\u8f91\u4e4b\u524d\u4f1a\u521b\u5efa\u4e00\u4e2a\u5907\u4efd\u6587\u4ef6\u3002 linuxmi@linuxmi ~\/www.linuxmi.com % echo [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-61246","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61246","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=61246"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/61246\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=61246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=61246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=61246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}