1) \u5982\u4f55\u5220\u9664\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5220\u9664\u6587\u4ef6\u9996\u884c\u3002<\/p>\n
N \u8868\u793a\u6587\u4ef6\u4e2d\u7684\u7b2c N \u884c\uff0cd \u9009\u9879\u5728 sed \u547d\u4ee4\u4e2d\u7528\u4e8e\u5220\u9664\u4e00\u884c\u3002<\/p>\n
\u8bed\u6cd5\uff1a<\/p>\n
sed 'Nd' file\r\n<\/pre>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u7684\u7b2c\u4e00\u884c\u3002<\/p>\n
# sed '1d' sed-demo.txt\r\n Unix Operating System\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n2) \u5982\u4f55\u5220\u9664\u6587\u4ef6\u7684\u6700\u540e\u4e00\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\u5220\u9664\u6587\u4ef6\u6700\u540e\u4e00\u884c\u3002<\/p>\n
$ \u7b26\u53f7\u8868\u793a\u6587\u4ef6\u7684\u6700\u540e\u4e00\u884c\u3002<\/p>\n
\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u7684\u6700\u540e\u4e00\u884c\u3002<\/p>\n
# sed '$d' sed-demo.txt\r\n Linux Operating System\r\n Unix Operating System\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n<\/pre>\n3) \u5982\u4f55\u5220\u9664\u6307\u5b9a\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u7684\u7b2c 3 \u884c\u3002<\/p>\n
# sed '3d' sed-demo.txt\r\n Linux Operating System\r\n Unix Operating System\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n4) \u5982\u4f55\u5220\u9664\u6307\u5b9a\u8303\u56f4\u5185\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u7684\u7b2c 5 \u5230 7 \u884c\u3002<\/p>\n
# sed '5,7d' sed-demo.txt\r\n Linux Operating System\r\n Unix Operating System\r\n RHEL\r\n Red Hat\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n5) \u5982\u4f55\u5220\u9664\u591a\u884c\u5185\u5bb9\uff1f<\/strong><\/div>\nsed \u547d\u4ee4\u80fd\u591f\u5220\u9664\u7ed9\u5b9a\u884c\u7684\u96c6\u5408\u3002<\/p>\n
\u672c\u4f8b\u4e2d\uff0c\u4e0b\u9762\u7684 sed \u547d\u4ee4\u5220\u9664\u4e86\u7b2c 1 \u884c\u3001\u7b2c 5 \u884c\u3001\u7b2c 9 \u884c\u548c\u6700\u540e\u4e00\u884c\u3002<\/p>\n
# sed '1d;5d;9d;$d' sed-demo.txt\r\n Unix Operating System\r\n RHEL\r\n Red Hat\r\n Arch Linux\r\n CentOS\r\n Debian\r\n<\/pre>\n5a) \u5982\u4f55\u5220\u9664\u6307\u5b9a\u8303\u56f4\u4ee5\u5916\u7684\u884c\uff1f<\/strong><\/span><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u7b2c 3 \u5230 6 \u884c\u8303\u56f4\u4ee5\u5916\u7684\u6240\u6709\u884c\u3002<\/p>\n
# sed '3,6!d' sed-demo.txt\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n<\/pre>\n6) \u5982\u4f55\u5220\u9664\u7a7a\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u7684\u7a7a\u884c\u3002<\/p>\n
# sed '\/^$\/d' sed-demo.txt\r\n Linux Operating System\r\n Unix Operating System\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n7) \u5982\u4f55\u5220\u9664\u5305\u542b\u67d0\u4e2a\u6a21\u5f0f\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u5339\u914d\u5230 System \u6a21\u5f0f\u7684\u884c\u3002<\/p>\n
# sed '\/System\/d' sed-demo.txt\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n8) \u5982\u4f55\u5220\u9664\u5305\u542b\u5b57\u7b26\u4e32\u96c6\u5408\u4e2d\u67d0\u4e2a\u5b57\u7b26\u4e32\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 sed-demo.txt \u4e2d\u5339\u914d\u5230 System \u6216 Linux \u8868\u8fbe\u5f0f\u7684\u884c\u3002<\/p>\n
# sed '\/System\\|Linux\/d' sed-demo.txt\r\n RHEL\r\n Red Hat\r\n Fedora\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n9) \u5982\u4f55\u5220\u9664\u4ee5\u6307\u5b9a\u5b57\u7b26\u5f00\u5934\u7684\u884c\uff1f<\/strong><\/div>\n\u4e3a\u4e86\u6d4b\u8bd5\uff0c\u6211\u521b\u5efa\u4e86 sed-demo-1.txt \u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u5185\u5bb9\u3002<\/p>\n
# cat sed-demo-1.txt\r\nLinux Operating System\r\nUnix Operating System\r\nRHEL\r\nRed Hat\r\nFedora\r\ndebian\r\nubuntu\r\nArch Linux - 1\r\n2 - Manjaro\r\n3 4 5 6\r\n<\/pre>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u4ee5 R \u5b57\u7b26\u5f00\u5934\u7684\u6240\u6709\u884c\u3002<\/p>\n
# sed '\/^R\/d' sed-demo-1.txt\r\nLinux Operating System\r\nUnix Operating System\r\nFedora\r\ndebian\r\nubuntu\r\nArch Linux - 1\r\n2 - Manjaro\r\n3 4 5 6\r\n<\/pre>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 R \u6216\u8005 F \u5b57\u7b26\u5f00\u5934\u7684\u6240\u6709\u884c\u3002<\/p>\n
# sed '\/^[RF]\/d' sed-demo-1.txt\r\nLinux Operating System\r\nUnix Operating System\r\ndebian\r\nubuntu\r\nArch Linux - 1\r\n2 - Manjaro\r\n3 4 5 6\r\n<\/pre>\n10) \u5982\u4f55\u5220\u9664\u4ee5\u6307\u5b9a\u5b57\u7b26\u7ed3\u5c3e\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 m \u5b57\u7b26\u7ed3\u5c3e\u7684\u6240\u6709\u884c\u3002<\/p>\n
# sed '\/m$\/d' sed-demo.txt\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664 x \u6216\u8005 m \u5b57\u7b26\u7ed3\u5c3e\u7684\u6240\u6709\u884c\u3002<\/p>\n
# sed '\/[xm]$\/d' sed-demo.txt\r\n RHEL\r\n Red Hat\r\n Fedora\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n11) \u5982\u4f55\u5220\u9664\u6240\u6709\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u6240\u6709\u5927\u5199\u5b57\u6bcd\u5f00\u5934\u7684\u884c\u3002<\/p>\n
# sed '\/^[A-Z]\/d' sed-demo-1.txt\r\ndebian\r\nubuntu\r\n2 - Manjaro\r\n3 4 5 6\r\n<\/pre>\n12) \u5982\u4f55\u5220\u9664\u6307\u5b9a\u8303\u56f4\u5185\u5339\u914d\u6a21\u5f0f\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u7b2c 1 \u5230 6 \u884c\u4e2d\u5305\u542b Linux \u8868\u8fbe\u5f0f\u7684\u884c\u3002<\/p>\n
# sed '1,6{\/Linux\/d;}' sed-demo.txt \r\n Unix Operating System\r\n RHEL\r\n Red Hat\r\n Fedora\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n13) \u5982\u4f55\u5220\u9664\u5339\u914d\u6a21\u5f0f\u7684\u884c\u53ca\u5176\u4e0b\u4e00\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u5305\u542b System \u8868\u8fbe\u5f0f\u7684\u884c\u4ee5\u53ca\u5b83\u7684\u4e0b\u4e00\u884c\u3002<\/p>\n
# sed '\/System\/{N;d;}' sed-demo.txt\r\n RHEL\r\n Red Hat\r\n Fedora\r\n Arch Linux\r\n CentOS\r\n Debian\r\n Ubuntu\r\n openSUSE\r\n<\/pre>\n14) \u5982\u4f55\u5220\u9664\u5305\u542b\u6570\u5b57\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u6240\u6709\u5305\u542b\u6570\u5b57\u7684\u884c\u3002<\/p>\n
# sed '\/[0-9]\/d' sed-demo-1.txt\r\nLinux Operating System\r\nUnix Operating System\r\nRHEL\r\nRed Hat\r\nFedora\r\ndebian\r\nubuntu\r\n<\/pre>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u6240\u6709\u4ee5\u6570\u5b57\u5f00\u5934\u7684\u884c\u3002<\/p>\n
# sed '\/^[0-9]\/d' sed-demo-1.txt\r\nLinux Operating System\r\nUnix Operating System\r\nRHEL\r\nRed Hat\r\nFedora\r\ndebian\r\nubuntu\r\nArch Linux - 1\r\n<\/pre>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u6240\u6709\u4ee5\u6570\u5b57\u7ed3\u5c3e\u7684\u884c\u3002<\/p>\n
# sed '\/[0-9]$\/d' sed-demo-1.txt \r\nLinux Operating System\r\nUnix Operating System\r\nRHEL\r\nRed Hat\r\nFedora\r\ndebian\r\nubuntu\r\n - Manjaro\r\n<\/pre>\n15) \u5982\u4f55\u5220\u9664\u5305\u542b\u5b57\u6bcd\u7684\u884c\uff1f<\/strong><\/div>\n\u4f7f\u7528\u4ee5\u4e0b sed \u547d\u4ee4\u5220\u9664\u6240\u6709\u5305\u542b\u5b57\u6bcd\u7684\u884c\u3002<\/p>\n
# sed '\/[A-Za-z]\/d' sed-demo-1.txt \r\n3 4 5 6 \r\n<\/pre>\nvia: https:\/\/www.2daygeek.com\/linux-remove-delete-lines-in-file-sed-command\/<\/p>\n
\u4f5c\u8005\uff1aMagesh Maruthamuthu \u9009\u9898\uff1alujun9972 \u8bd1\u8005\uff1ahello-wn \u6821\u5bf9\uff1awxy<\/p>\n","protected":false},"excerpt":{"rendered":"
\u5982\u4f55\u4f7f\u7528sed\u547d\u4ee4\u5220\u9664\u6587\u4ef6\u4e2d\u7684\u884c Sed \u4ee3\u8868\u6d41\u7f16\u8f91\u5668Stream Editor\uff0c\u5e38\u7528\u4e8e Linux \u4e2d\u57fa\u672c\u7684 […]<\/p>\n","protected":false},"author":1898,"featured_media":157761,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[439],"class_list":["post-157757","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-sed"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/157757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=157757"}],"version-history":[{"count":11,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/157757\/revisions"}],"predecessor-version":[{"id":160432,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/157757\/revisions\/160432"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/157761"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=157757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=157757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=157757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}