{"id":2117,"date":"2019-05-24T23:31:02","date_gmt":"2019-05-24T15:31:02","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=2117"},"modified":"2022-05-08T15:50:49","modified_gmt":"2022-05-08T07:50:49","slug":"sed","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/sed","title":{"rendered":"sed\u547d\u4ee4 – \u6279\u91cf\u7f16\u8f91\u6587\u672c\u6587\u4ef6"},"content":{"rendered":"\n

sed\u547d\u4ee4\u6765\u81ea\u4e8e\u82f1\u6587\u8bcd\u7ec4\u201cstream editor\u201d\u7684\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8e\u5229\u7528\u8bed\u6cd5\/\u811a\u672c\u5bf9\u6587\u672c\u6587\u4ef6\u8fdb\u884c\u6279\u91cf\u7684\u7f16\u8f91\u64cd\u4f5c\u3002sed\u547d\u4ee4\u6700\u521d\u7531\u8d1d\u5c14\u5b9e\u9a8c\u5ba4\u5f00\u53d1\uff0c\u540e\u88ab\u4f17\u591aLinux\u7cfb\u7edf\u63a5\u7eb3\u96c6\u6210\uff0c\u80fd\u591f\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u6587\u4ef6\u8fdb\u884c\u6279\u91cf\u7f16\u8f91\uff0c\u8ba9\u9700\u8981\u91cd\u590d\u7684\u5de5\u4f5c\u4e0d\u518d\u6d6a\u8d39\u65f6\u95f4\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>sed \u53c2\u6570 \u6587\u4ef6<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n

-e\u6216--expression=<script><\/td>\u4ee5\u6307\u5b9a\u7684\u811a\u672c\u6765\u5904\u7406\u8f93\u5165\u7684\u6587\u672c\u6587\u4ef6<\/td><\/tr>
-f<script\u6587\u4ef6>\u6216--file=<script\u6587\u4ef6> <\/td>\u4ee5\u6307\u5b9a\u7684\u811a\u672c\u6587\u4ef6\u6765\u5904\u7406\u8f93\u5165\u7684\u6587\u672c\u6587\u4ef6<\/td><\/tr>
-h\u6216--help<\/td>\u663e\u793a\u5e2e\u52a9<\/td><\/tr>
-n\u6216--quiet\u6216--silent <\/td>\u4ec5\u663e\u793ascript\u5904\u7406\u540e\u7684\u7ed3\u679c<\/td><\/tr>
-V\u6216--version<\/td>\u663e\u793a\u7248\u672c\u4fe1\u606f<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u67e5\u627e\u6307\u5b9a\u6587\u4ef6\u4e2d\u5e26\u6709\u67d0\u4e2a\u5173\u952e\u8bcd\u7684\u884c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# cat -n anaconda-ks.cfg | sed -n '\/root\/p'<\/strong>\r\n    20\trootpw --iscrypted $6$c2VGkv\/8C3IEwtRt$iPEjNXml6v5KEmcM9okIT.Op9\/LEpFejqR.kmQWAVX7fla3roq.3MMVKDahnv0l\/pONz2WMNecy17WJ8Ib0iO1\r\n    40\tpwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty\r<\/pre>\n\n\n\n

\u66ff\u6362\u6307\u5b9a\u6587\u4ef6\u4e2d\u67d0\u4e2a\u5173\u952e\u8bcd\u6210\u5927\u5199\u5f62\u5f0f\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# sed 's\/root\/ROOT\/g' anaconda-ks.cfg<\/strong>\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u8bfb\u53d6\u6307\u5b9a\u6587\u4ef6\uff0c\u5220\u9664\u6240\u6709\u5e26\u6709\u67d0\u4e2a\u5173\u952e\u8bcd\u7684\u884c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# sed '\/root\/d' anaconda-ks.cfg <\/strong>\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u8bfb\u53d6\u6307\u5b9a\u6587\u4ef6\uff0c\u5728\u7b2c4\u884c\u540e\u63d2\u5165\u4e00\u884c\u65b0\u5185\u5bb9\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# sed -e 4a\\NewLine anaconda-ks.cfg <\/strong>\n#version=RHEL8\nignoredisk --only-use=sda\nautopart --type=lvm\n# Partition clearing information\nNewLine\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u8bfb\u53d6\u6307\u5b9a\u6587\u4ef6\uff0c\u5728\u7b2c4\u884c\u540e\u63d2\u5165\u591a\u884c\u65b0\u5185\u5bb9\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# cat anaconda-ks.cfg  | sed -e '4a NewLine1 \\<\/strong>\n> NewLine2 \\\n> NewLine3 '\n#version=RHEL8\nignoredisk --only-use=sda\nautopart --type=lvm\n# Partition clearing information\nNewLine1 \nNewLine2 \nNewLine3 \nclearpart --none --initlabel\n# Use graphical install\ngraphical\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u8bfb\u53d6\u6307\u5b9a\u6587\u4ef6\uff0c\u5220\u9664\u7b2c2-5\u884c\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# cat  -n \/etc\/passwd | sed '2,5d' <\/strong>\n     1\troot:x:0:0:root:\/root:\/bin\/bash\n     6\tsync:x:5:0:sync:\/sbin:\/bin\/sync\n     7\tshutdown:x:6:0:shutdown:\/sbin:\/sbin\/shutdown\n     8\thalt:x:7:0:halt:\/sbin:\/sbin\/halt\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u8bfb\u53d6\u6307\u5b9a\u6587\u4ef6\uff0c\u66ff\u6362\u7b2c2-5\u884c\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# sed '2,5c NewSentence' anaconda-ks.cfg <\/strong>\n#version=RHEL8\nNewSentence\n# Use graphical install\ngraphical\nrepo --name=\"AppStream\" --baseurl=file:\/\/\/run\/install\/repo\/AppStream\n# Use CDROM installation media\ncdrom\n\u2026\u2026\u2026\u2026\u2026\u2026\u7701\u7565\u90e8\u5206\u8f93\u51fa\u4fe1\u606f\u2026\u2026\u2026\u2026\u2026\u2026<\/pre>\n\n\n\n

\u6307\u5b9a\u8bfb\u53d6\u67d0\u4e2a\u6587\u4ef6\u7684\u7b2c3-7\u884c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# sed -n '3,7p' anaconda-ks.cfg<\/strong> \nautopart --type=lvm\n# Partition clearing information\nclearpart --none --initlabel\n# Use graphical install\ngraphical<\/pre>\n","protected":false},"excerpt":{"rendered":"

sed\u547d\u4ee4\u6765\u81ea\u4e8e\u82f1\u6587\u8bcd\u7ec4\u201cstream editor\u201d\u7684\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8e\u5229\u7528\u8bed\u6cd5\/\u811a\u672c\u5bf9\u6587\u672c\u6587\u4ef6\u8fdb\u884c\u6279\u91cf\u7684\u7f16 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/2117"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=2117"}],"version-history":[{"count":19,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/2117\/revisions"}],"predecessor-version":[{"id":9345,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/2117\/revisions\/9345"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=2117"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=2117"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=2117"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}