{"id":1691,"date":"2024-05-08T17:51:58","date_gmt":"2024-05-08T09:51:58","guid":{"rendered":"http:\/\/oneai.eu.org\/?p=1691"},"modified":"2024-05-08T17:51:58","modified_gmt":"2024-05-08T09:51:58","slug":"sed-%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/oneai.eu.org\/?p=1691","title":{"rendered":"sed \u7684\u4f7f\u7528"},"content":{"rendered":"<p>\u5728Linux\u4e0a\u5de5\u4f5c,\u9700\u8981\u52a8\u6001\u7684\u5904\u7406\u6587\u672c,\u800c\u4e0d\u5fc5\u4f7f\u7528\u5b8c\u5907\u7684\u6587\u672c\u7f16\u8f91\u5668,\u5728\u8fd9\u6837\u60c5\u51b5\u4e00\u4e0a\uff0c\u62e5\u6709\u4e00\u4e2a\u80fd\u591f\u65b9\u4fbf\u5730\u683c\u5f0f\u5316\uff0c\u63d2\u5165\uff0c\u4fee\u6539\uff0c\u5220\u9664\uff0c\u6587\u672c\u7684\u7b80\u5355\u547d\u4ee4\u884c\u7f16\u8f91\u5668\u5c31\u5f88\u6709\u7528\u4e86\u3002<\/p>\n<p>linux\u4e0a\u6700\u5e38\u7528\u7684\u4e24\u4e2a\u6d41\u7f16\u8f91\u5668sed\u548cawk\u5c31\u662f\u8fd9\u6837\u7684\u5de5\u5177\u3002\u672c\u6587\u4e3b\u8981\u8ba8\u8bbased\u7684\u7528\u6cd5\u3002<\/p>\n<p>sed\u7f16\u8f91\u5668\u79f0\u4e3a\u6d41\u7f16\u8f91\u5668\uff0c\u5b83\u6bcf\u6b21\u53ea\u5904\u7406\u4e00\u884c\u6570\u636e\uff0c\u5c06\u8be5\u6570\u636e\u4e0e\u6240\u63d0\u4f9b\u7684\u7f16\u8f91\u5668\u547d\u4ee4\u8fdb\u884c\u5339\u914d\uff0c\u6839\u636e\u547d\u4ee4\u4fee\u6539\u6570\u636e\u6d41\u4e2d\u7684\u6570\u636e\uff0c\u7136\u540e\u5c06\u65b0\u6570\u636e\u8f93\u51fa\u5230stdout\u4e0a\uff0c\u4e4b\u540e\u5b83\u5c06\u8bfb\u53d6\u4e0b\u4e00\u884c\u6570\u636e\uff0c\u5e76\u91cd\u590d\u4e0a\u8ff0\u7684\u52a8\u4f5c\u3002\u5904\u7406\u5b8c\u6d41\u6570\u636e\u4e2d\u7684\u5168\u90e8\u6570\u636e\u4e4b\u540e\uff0c\u6d41\u7f16\u8f91\u5668\u505c\u6b62\u3002<\/p>\n<p>sed\u547d\u4ee4\u4e0d\u4fee\u6539\u539f\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u53ea\u662f\u5c06\u4fee\u6539\u7684\u7ed3\u679c\u663e\u793a\u51fa\u6765\u800c\u5df2\uff0c\u539f\u6587\u4ef6\u4e0d\u4f1a\u6539\u53d8\u3002<\/p>\n<p>sed\u7684\u547d\u4ee4\u683c\u5f0f\u662f\uff1a<\/p>\n<p>sed options scripts file<\/p>\n<p>options\u53c2\u6570\u5141\u8bb8\u81ea\u5b9a\u4e49sed\u7684\u547d\u4ee4\u884c\u4e3a\uff0c\u5b83\u5305\u542b\u7684\u9009\u9879\u5982\u4e0b\uff1a<\/p>\n<p>\u9009\u9879 \u63cf\u8ff0<br \/>\n-e  scripts \u5c06\u811a\u672c\u4e2d\u6307\u5b9a\u7684\u547d\u4ee4\u6dfb\u52a0\u5230\u5904\u7406\u8f93\u5165\u65f6\u6267\u884c\u7684\u547d\u4ee4\u4e2d<br \/>\n-f  file \u5c06\u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u547d\u4ee4\u6dfb\u52a0\u5230\u5904\u7406\u8f93\u5165\u65f6\u6267\u884c\u7684\u547d\u4ee4<br \/>\n-n \u4e0d\u9700\u8981\u4e3a\u6bcf\u4e2a\u547d\u4ee4\u4ea7\u751f\u8f93\u51fa\uff0c\u4f46\u8981\u7b49\u5f85\u6253\u5370\u547d\u4ee4\uff0c\u7ecf\u5e38\u548c-p \u4e00\u8d77\u4f7f\u7528 <\/p>\n<p>scripts\u53c2\u6570\u6307\u5b9a\u8981\u5e94\u7528\u4e8e\u6d41\u6570\u636e\u7684\u5355\u4e2a\u547d\u4ee4\u3002\u5982\u679c\u9700\u8981\u591a\u4e2a\u547d\u4ee4\uff0c\u5c31\u5fc5\u987b\u4f7f\u7528 -e \u547d\u4ee4\uff0c \u6216\u8005\u4f7f\u7528-f \u9009\u9879\u5728\u5355\u72ec\u7684\u6587\u4ef6\u4e2d\u6307\u5b9a\u3002<\/p>\n<p>\u4e00\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u5b9a\u4e49\u7f16\u8f91\u5668\u547d\u4ee4\u3002<\/p>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0csed\u7f16\u8f91\u5668\u5c06\u6307\u5b9a\u7684\u547d\u4ee4\u5e94\u7528\u4e8eSTDIN\u8f93\u5165\u6d41\u3002\u8fd9\u5c31\u5141\u8bb8\u5c06\u6570\u636e\u901a\u8fc7\u7ba1\u9053\u4f20\u9001\u7ed9sed\u7f16\u8f91\u5668\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<p>\u5982\u4e0b\u9762\u7684\u4e00\u4e2a\u4f8b\u5b50\u3002\u672c\u6587\u6240\u4ee5\u7684\u4f8b\u5b50\u90fd\u5728root\u7684\u5bb6\u76ee\u5f55\u4e0b\u8fdb\u884c\u7684\u3002<\/p>\n<p>[root@linuxmoon ~]# echo &quot;this is a test page&quot; | sed 's\/page\/home\/'<br \/>\nthis is a test home<\/p>\n<p>\u8be5\u4f8bsed\u4f7f\u7528\u4e86 s \u547d\u4ee4\u3002s \u7528\u4e8e\u5c06\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u66ff\u6362\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u672c\u4f8bhome\u66ff\u6362page<\/p>\n<p>\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u4e5f\u53ef\u4ee5\u6709\u7a7a\u683c\u3002\u5982\u4e0bred apple\u66ff\u6362apple<\/p>\n<p>[root@linuxmoon ~]# echo &quot;this is an big apple&quot; | sed 's\/apple\/red apple\/'<br \/>\nthis is an big red apple<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5e76\u5904\u7406\uff0c\u4f46\u539f\u6587\u4ef6\u4e0d\u4f1a\u4fee\u6539\u3002\u5982\u4e0b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data1<br \/>\nthis is an big apple<br \/>\nthis is an big red apple<br \/>\nthis is an small apple<br \/>\nthis ia an small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]# sed 's\/apple\/bird\/' data1<br \/>\nthis is an big bird<br \/>\nthis is an big red bird<br \/>\nthis is an small bird<br \/>\nthis ia an small red bird<br \/>\nthis is no an bird<\/p>\n<p>\u67e5\u770b\u539f\u6587\u4ef6\uff0c\u4ecd\u7136\u662f\u539f\u6765\u7684\u6570\u636e<br \/>\n[root@linuxmoon ~]# cat data1<br \/>\nthis is an big apple<br \/>\nthis is an big red apple<br \/>\nthis is an small apple<br \/>\nthis ia an small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u672c\u4f8b\u4e2d\u628a\u6587\u4ef6data1\u4e2d\u7684\u6240\u6709\u7684apple\u5c31\u66ff\u6362\u6210\u4e86bird<\/p>\n<p>2.\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u591a\u4e2a\u547d\u4ee4<\/p>\n<p>[root@linuxmoon ~]# cat data1<br \/>\nthis is an big apple<br \/>\nthis is an big red apple<br \/>\nthis is an small apple<br \/>\nthis ia an small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]# sed -e 's\/big\/very big\/;s\/small\/very small\/' data1<br \/>\nthis is an very big apple<br \/>\nthis is an very big red apple<br \/>\nthis is an very small apple<br \/>\nthis ia an very small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u4e24\u4e2a\u547d\u4ee4\u5c06\u540c\u65f6\u4f5c\u7528\u4e8e\u6587\u4ef6\u4e2d\u7684\u6bcf\u4e00\u884c\u6570\u636e\u3002\u547d\u4ee4\u5fc5\u987b\u7528\u5206\u53f7\u9694\u5f00\uff0c\u4e14\u5728\u547d\u4ee4\u7ed3\u5c3e\u548c\u5206\u53f7\u4e4b\u95f4\u4e0d\u80fd\u6709\u7a7a\u683c\u3002<\/p>\n<p>\u4e5f\u53ef\u4ee5\u7528\u547d\u63d0\u793a\u7b26\uff0c\u5982\u4e0b\uff1a<\/p>\n<p>root@linuxmoon ~]# cat data1<br \/>\nthis is an big apple<br \/>\nthis is an big red apple<br \/>\nthis is an small apple<br \/>\nthis ia an small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]# sed -e '<\/p>\n<blockquote>\n<p>s\/big\/very big\/<br \/>\ns\/small\/very small\/' data1<br \/>\nthis is an very big apple<br \/>\nthis is an very big red apple<br \/>\nthis is an very small apple<br \/>\nthis ia an very small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]#<\/p>\n<\/blockquote>\n<p>3.\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7f16\u8f91\u5668\u547d\u4ee4<\/p>\n<p>\u4f8b\u5982\u4e0a\u9762\u4f8b\u5b50\uff0c\u6211\u4eec\u628a\u547d\u4ee4sed -e 's\/big\/very big\/;s\/small\/very small\/' data1 \u5199\u5165\u6587\u4ef6file1\u4e2d\u3002<\/p>\n<p>[root@linuxmoon ~]# cat file1<br \/>\ns\/big\/very big\/<br \/>\ns\/small\/very small\/<br \/>\n[root@linuxmoon ~]# sed -f file1 data1<br \/>\nthis is an very big apple<br \/>\nthis is an very big red apple<br \/>\nthis is an very small apple<br \/>\nthis ia an very small red apple<br \/>\nthis is no an apple<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4e0d\u9700\u8981\u5728\u6bcf\u4e2a\u547d\u4ee4\u540e\u653e\u4e00\u4e2a\u5206\u53f7\u3002sed\u77e5\u9053\u4e00\u884c\u662f\u4e00\u6761\u547d\u4ee4\u3002<\/p>\n<p>sed\u7f16\u8f91\u5668\u7684\u57fa\u7840\u77e5\u8bc6\uff1a<\/p>\n<p>1.\u66ff\u6362\u6807\u8bb0<\/p>\n<p>\u5bf9\u4e8e\u66ff\u6362\u547d\u4ee4\u66ff\u6362\u6587\u672c\u5b57\u7b26\uff0c\u6709\u4e00\u4e2a\u5c0f\u95ee\u9898\uff0c\u9996\u5148\u5148\u5efa\u7acb\u6587\u4ef6data2\u3002\u4ee5\u4f5c\u6f14\u793a\u3002\u8bf7\u770b\u4e0b\u9762\u7684\u4f8b\u5b50\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second test of the test file<br \/>\n[root@linuxmoon ~]# sed 's\/test\/hello\/' data2<br \/>\nthis is the  hello of the test file<br \/>\nthis is the second hello of the test file<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u6211\u4eec\u53d1\u73b0\u6bcf\u4e00\u884c\u7684\u7b2c\u4e00\u4e2atest\u88ab\u66ff\u6362\u6389\u4e86\uff0c\u4f46\u662f\u6bcf\u4e00\u884c\u7684\u7b2c\u4e8c\u4e2a\u6216\u8005\u7b2c\u4e09\u4e2a\u3002\u3002\u3002\u3002\u90fd\u6ca1\u6709\u88ab\u66ff\u6362\u3002<\/p>\n<p>\u5373\u53ea\u66ff\u6362\u6bcf\u4e00\u884c\u7684\u7b2c\u4e00\u4e2a\u88ab\u5339\u914d\u7684test<\/p>\n<p>\u5982\u679c\u60f3\u8981\u5168\u90e8\u66ff\u6362\uff0c\u9700\u8981\u7528\u66ff\u6362\u6807\u8bb0(flags)\u3002\u66ff\u6362\u4f7f\u7528\u5728\u66ff\u6362\u547d\u4ee4\u4e4b\u540e\uff1a<\/p>\n<p>s\/pattern\/replace\/flags<\/p>\n<p>\u53ef\u7528\u7684flags\u67094\u79cd<\/p>\n<p>\u6570\u5b57:\u8868\u793a\u66ff\u6362\u7b2c\u51e0\u4e2a<br \/>\ng    :\u5168\u5c40\u66ff\u6362<br \/>\np    :\u8868\u793a\u6253\u5370\u539f\u59cb\u884c\u7684\u5185\u5bb9<br \/>\nw file :\u5c06\u66ff\u6362\u7684\u7ed3\u679c\u5199\u5165\u6587\u4ef6\u4e2d<br \/>\n\u5728\u7b2c\u4e00\u79cd\u7c7b\u578b\u4e2d\uff0c\u8868\u793a\u53ef\u4ee5\u66ff\u6362\u7684\u7b2c\u51e0\u4e2a\u5b57\u7b26\u4e32\uff0c\u5982\u4e0b\u4f8b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second test of the test file<br \/>\n[root@linuxmoon ~]# sed 's\/test\/hello\/2' data2<br \/>\nthis is the  test of the hello file<br \/>\nthis is the second test of the hello file<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u5728\u7b2c\u4e8c\u79cd\u7c7b\u578b\u4e2d\uff0cg \u8868\u793a\u5168\u90e8\u66ff\u6362:\u5982\u4e0b\u4f8b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second test of the test file<br \/>\n[root@linuxmoon ~]# sed 's\/test\/hello\/g' data2<br \/>\nthis is the  hello of the hello file<br \/>\nthis is the second hello of the hello file<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u5728\u7b2c\u4e09\u79cd\u7c7b\u578b\u4e2d\uff0cp \u8868\u793a\u53ea\u6253\u5370\u5339\u914d\u7684\u884c\uff0c\u7ecf\u5e38\u548c-n\u4e00\u8d77\u4f7f\u7528\u3002\u5982\u4e0b\u4f8b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second test of the test file<br \/>\n[root@linuxmoon ~]# sed -n 's\/second\/yes second\/p' data2<br \/>\nthis is the yes second test of the test file<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u672c\u4f8b\u4e2d\uff0c\u53ea\u6253\u5370\u51fa\u4e86\u88ab\u5339\u914d\u7684\u884c\uff0c\u672a\u88ab\u5339\u914d\u7684\u884c\u5219\u4e0d\u6253\u5370\u3002<\/p>\n<p>\u5728\u7b2c\u56db\u79cd\u7c7b\u578b\u4e2d\uff0cw \u8868\u793a\u5c06sed\u4fee\u6539\u540e\u7684\u5185\u5bb9\u4fdd\u5b58\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\u3002\u5982\u4e0b\u4f8b<\/p>\n<p>[root@linuxmoon ~]# cat data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second test of the test file<br \/>\n[root@linuxmoon ~]# sed 's\/test\/hello\/w hello.txt' data2<br \/>\nthis is the  hello of the test file<br \/>\nthis is the second hello of the test file<br \/>\n[root@linuxmoon ~]# cat hello.txt<br \/>\nthis is the  hello of the test file<br \/>\nthis is the second hello of the test file<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u672c\u4f8b\u5c06\u4fee\u6539\u540e\u7684\u5185\u5bb9\u4fdd\u5b58\u5230\u4e86hello.txt\u6587\u4ef6\u4e2d<\/p>\n<p>2.\u66ff\u6362\u5b57\u7b26<\/p>\n<p>\u6709\u65f6\u5019\u5728Linux\u4e2d\u4f1a\u9047\u5230\u4e0d\u5bb9\u6613\u66ff\u6362\u7684\u5b57\u7b26\u3002\u6700\u5e38\u7528\u7684\u4e00\u4e2a\u4f8b\u5b50\u5c31\u662f\u659c\u6760\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u60f3\u8981\u628a\/etc\/passwd\u4e0b\u7684bash shell\u66ff\u6362\u6210cshell\uff0c\u5fc5\u987b\u8fd9\u6837\u505a:<\/p>\n<p>[root@linuxmoon ~]# sed 's\/\\\/bin\\\/bash\/\\\/bin\\\/cshell\/g' \/etc\/passwd<\/p>\n<p>\u8fd9\u6837\u4f1a\u5f88\u4e71\uff0c\u8fd8\u5bb9\u6613\u641e\u6df7\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u7b26\u5b9a\u754c\u7b26\u3002\u5982\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u53ef\u4ee5\u7528 \u201c\uff01\u201d\u4f5c\u5b9a\u754c\u7b26<\/p>\n<p>[root@linuxmoon ~]# sed 's!\/bin\/bash!\/bin\/cshell!' \/etc\/passwd<\/p>\n<p>3.\u884c\u5bfb\u5740<\/p>\n<p>\u6709\u65f6\u5019\u4ec5\u4ec5\u60f3\u4fee\u6539\u67d0\u4e00\u884c\u6216\u67d0\u4e9b\u6307\u5b9a\u7684\u884c\u3002\u90a3\u4e48\u5c31\u53ef\u4ee5\u7528\u884c\u5bfb\u5740\u4e86\u3002\u884c\u5bfb\u5740\u5206\u4e3a\u4e24\u7c7b\uff1a<\/p>\n<p>1.\u884c\u7684\u6570\u503c\u8303\u56f4<\/p>\n<p>2.\u7b5b\u9009\u884c\u7684\u6587\u672c\u6a21\u5f0f<\/p>\n<pre><code>    1.\u884c\u7684\u6570\u503c\u8303\u56f4<\/code><\/pre>\n<p>[root@linuxmoon ~]# cat data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]# sed '2s\/apple\/dog\/' data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u672c\u4f8b\u4e2d\uff0c\u53ea\u66ff\u6362\u7b2c2\u884c\uff0c\u4e0b\u9762\u662f\u4e00\u4e2a\u4f8b\u5b50\uff0c\u66ff\u6362\u7b2c2\u884c\u5230\u7b2c4\u884c\u3002\u4f7f\u7528\u7684\u662f\u884c\u5730\u5740\u8303\u56f4\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]# sed '2,4s\/apple\/dog\/' data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u5982\u679c\u8981\u5c06\u547d\u4ee4\u5e94\u7528\u4e8e\u6587\u672c\u5185\u4ece\u67d0\u4e00\u884c\u5230\u6700\u540e\u4e00\u884c\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u7279\u6b8a\u5730\u5740 $ \u7b26\u53f7\u3002\u4e0b\u9762\u4f8b\u5b50\u662f\u4ece\u7b2c2 \u884c\u5230\u6700\u540e\u4e00\u884c\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]# sed '2,$s\/apple\/dog\/' data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an dog on the desk<br \/>\nthere is an dog on the desk<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>2.\u7b5b\u9009\u884c\u7684\u6587\u672c\u6a21\u5f0f<\/p>\n<p>\u9650\u5236\u67d0\u4e9b\u547d\u4ee4\u5e94\u7528\u4e8e\u54ea\u4e9b\u884c\u3002<\/p>\n<p>\u547d\u4ee4\u683c\u5f0f\u4e3a\uff1a<\/p>\n<p>\/pattern\/command<\/p>\n<p>\u5fc5\u987b\u4f7f\u7528\u659c\u6760\u5c06\u6807\u8bb0\u6307\u5b9a\u7684pattern\uff0csed\u7f16\u8f91\u5668\u4ec5\u5c06\u8be5\u547d\u4ee4\u5e94\u7528\u4e8e\u5305\u542b\u6587\u672c\u6a21\u5f0f\u7684\u884c\u3002<\/p>\n<p>\u5982\u4e0b\u9762\u7684\u4f8b\u5b50\uff0c\u53ea\u66ff\u6362\u542b\u6709second\u7684\u884c\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second test of the test file<br \/>\n[root@linuxmoon ~]# sed '\/second\/s\/test\/hello\/' data2<br \/>\nthis is the  test of the test file<br \/>\nthis is the second hello of the test file<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u7ec4\u5408\u547d\u4ee4<\/p>\n<p>\u5982\u679c\u9700\u8981\u5728\u5355\u72ec\u4e00\u884c\u4e0a\u6267\u884c\u591a\u4e2a\u547d\u4ee4\uff0c\u8bf7\u4f7f\u7528\u5728\u62ec\u53f7\u5c06\u547d\u4ee4\u7ec4\u5408\u5728\u4e00\u8d77\u3002sed\u7f16\u8f91\u5668\u5c06\u5904\u7406\u5730\u5740\u884c\u4e0a\u5217\u51fa\u7684\u6240\u6709\u547d\u4ee4\uff1a<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]# sed '2{<\/p>\n<blockquote>\n<p>s\/apple\/banana\/<br \/>\ns\/desk\/bed\/<br \/>\n}' data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an banana on the bed<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]#<\/p>\n<\/blockquote>\n<p>\u672c\u4f8b\u4e2d\u5c06\u7b2c2\u884c\u4e0a\u7684apple,desk\u5206\u522b\u66ff\u6362\u4e3abanana,bed \uff0c\u4e24\u4e2a\u547d\u4ee4\u90fd\u5bf9\u8be5\u884c\u4f5c\u4e86\u5904\u7406\u3002\u5f53\u7136\u8fd8\u53ef\u4ee5\u4f7f\u7528\u884c\u5730\u5740\u8303\u56f4\u3002\u5982\u4e0b\u4f8b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\n[root@linuxmoon ~]# sed '3,${<\/p>\n<blockquote>\n<p>s\/apple\/banana\/<br \/>\ns\/desk\/bed\/<br \/>\n}' data3<br \/>\nthere is an apple on the desk<br \/>\nthere is an apple on the desk<br \/>\nthere is an banana on the bed<br \/>\nthere is an banana on the bed<br \/>\nthere is an banana on the bed<br \/>\n[root@linuxmoon ~]#<\/p>\n<\/blockquote>\n<p>\u672c\u4f8b\u4e2d\u628a\u7b2c3\u884c\u5230\u6700\u540e\u4e00\u884c\u7684\u6240\u6709\u7684apple,desk\u90fd\u66ff\u6362\u6210\u4e86banana,bed<\/p>\n<p>\u4e8c\uff1a\u5220\u9664\u884c<\/p>\n<p>\u5220\u9664\u547d\u4ee4\u4e3ad ,\u5373\u5220\u9664\u6587\u672c\u6d41\u4e2d\u7684\u7279\u5b9a\u884c<\/p>\n<p>\u7528\u6cd5\u5982\u4e0b<\/p>\n<p>\u793a\u4f8b1\uff1a\u5220\u9664\u7b2c3\u884c<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '3d' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b2\uff1a\u5220\u9664\u7b2c2\u884c\u5230\u7b2c4\u884c<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '2,4d' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b3\uff1a\u5220\u9664\u7b2c2\u884c\u5230\u6700\u540e\u4e00\u884c<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '2,$d' data4<br \/>\nthis is the a test line and is the 1<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b4\uff1a\u5220\u9664\u542b\u6709\u7279\u5b9a\u5b57\u7b26\u4e32\u7684\u884c\uff0c\u672c\u4f8b\u4e2d\u5220\u9664\u5305\u542b\u201dthe 2\u201d\u7684\u884c\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '\/the 2\/d' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u6ce8\uff1ased\u7f16\u8f91\u5668\u4e0d\u4f1a\u5904\u7406\u539f\u59cb\u6587\u4ef6\u3002\u6240\u5220\u9664\u7684\u6587\u672c\u884c\u4ec5\u4ecesed\u7f16\u8f91\u5668\u8f93\u51fa\u4e2d\u5220\u9664\uff0c\u800c\u539f\u59cb\u6587\u4ef6\u4ecd\u7136\u5305\u542b\u8fd9\u4e9b\u201c\u5df2\u5220\u9664\u7684\u884c\u201d\u3002<\/p>\n<p>\u4e09\uff1a\u63d2\u5165\u548c\u9644\u52a0\u6587\u672c<\/p>\n<p>\u540c\u5176\u5b83\u7684\u7f16\u8f91\u5668\u4e00\u884c\uff0csed\u7f16\u8f91\u5668\u53ef\u4ee5\u5411\u6587\u672c\u4e2d\u63d2\u5165\u548c\u9644\u52a0\u6587\u672c\u3002\u4e24\u4e2a\u64cd\u4f5c\u4e4b\u95f4\u7684\u5dee\u522b\u5f88\u5bb9\u6613\u6df7\u6dc6\u3002<\/p>\n<p>\u63d2\u5165\u547d\u4ee4( i ) \u5728\u6307\u5b9a\u884c\u7684\u524d\u9762\u63d2\u5165\u65b0\u7684\u4e00\u884c\u3002<br \/>\n\u9644\u52a0\u547d\u4ee4( a ) \u5728\u6307\u5b9a\u884c\u7684\u540e\u9762\u9644\u52a0\u65b0\u7684\u4e00\u884c\u3002<br \/>\n\u793a\u4f8b1\uff1a\u4f7f\u7528 i \u547d\u4ee4\uff0c\u5728\u6307\u5b9a\u884c\u7684\u524d\u9762\u63d2\u5165\u65b0\u7684\u4e00\u884c\u3002<\/p>\n<p>[root@linuxmoon ~]# echo &quot;this is a line&quot; |sed 'i test the command'<br \/>\ntest the command<br \/>\nthis is a line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b2\uff1a\u4f7f\u7528 a \u547d\u4ee4\uff0c\u5728\u6307\u5b9a\u884c\u7684\u540e\u9762\u9644\u52a0\u65b0\u7684\u4e00\u884c\u3002<\/p>\n<pre><code>   [root@linuxmoon ~]# echo \"this is a line\" |sed 'a test the command' \n   this is a line\n   test the command\n   [root@linuxmoon ~]#<\/code><\/pre>\n<p>\u793a\u4f8b3\uff1a\u4f7f\u7528\u6570\u5b57\u6307\u5b9a\u5728\u67d0\u4e00\u5177\u4f53\u7684\u884c\u63d2\u5165\u65b0\u7684\u4e00\u884c\u3002\u672c\u4f8b\u5728\u7b2c2\u884c\u63d2\u5165\u65b0\u7684\u4e00\u884c\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '2i this is the new line' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the new line<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b4\uff1a\u4f7f\u7528\u6570\u5b57\u6307\u5b9a\u5728\u67d0\u4e00\u5177\u4f53\u7684\u884c\u9644\u52a0\u65b0\u7684\u4e00\u884c\u3002\u672c\u4f8b\u5728\u7b2c2\u884c\u9644\u52a0\u65b0\u7684\u4e00\u884c\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '2a this is the new line' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the new line<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b5\uff1a\u5982\u679c\u6570\u636e\u6709\u591a\u884c\uff0c\u5728\u5c3e\u90e8\u9644\u52a0\u4e00\u884c\u3002\u53ef\u4ee5\u4f7f\u7528 $ \u7b26\u53f7\uff0c\u4f7f\u7528\u9644\u52a0\u547d\u4ee4 a \u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '$a this is the new line' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b6\uff1a\u5982\u679c\u6570\u636e\u6709\u591a\u884c\uff0c\u5728\u6700\u524d\u9762\u6dfb\u52a0\u65b0\u7684\u4e00\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u76f8\u540c\u7684\u601d\u8def\uff0c\u5728\u7b2c\u4e00\u884c\u63d2\u5165\u65b0\u4e00\u884c\u5373\u53ef\u3002\u4f7f\u7528\u63d2\u5165\u547d\u4ee4 i  .<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '1i this is the new line' data4<br \/>\nthis is the new line<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b7\uff1a\u5728\u6307\u5b9a\u7684\u884c\u524d\u9762\u63d2\u5165\u6216\u8005\u9644\u52a0\u591a\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u53cd\u659c\u6760\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '1i\\<\/p>\n<blockquote>\n<p>the first one\\<br \/>\nthe second one ' data4<br \/>\nthe first one<br \/>\nthe second one<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<\/blockquote>\n<p>\u56db\uff1a\u66f4\u6539\u884c<\/p>\n<pre><code> \u66f4\u6539\u884c\u547d\u4ee4\u5141\u8bb8\u66f4\u6539\u6570\u636e\u6d41\u4e2d\u7684\u6574\u884c\u6587\u672c\u3002\u6307\u5b9a\u8be5\u5730\u5740\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u6a21\u5f0f\u3002<\/code><\/pre>\n<p>\u793a\u4f8b1\uff1a\u66f4\u6539\u67d0\u4e00\u5177\u4f53\u7684\u884c\u3002\u672c\u4f8b\u4e2d\u66f4\u6539\u7b2c3\u884c\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '3c this is the changed line' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the changed line<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b2\uff1a\u4f7f\u7528\u6587\u672c\u6a21\u5f0f\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '\/the 3\/c this is the changed line' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the changed line<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b3\uff1a\u6587\u672c\u6a21\u5f0f\u5c06\u66f4\u6539\u4e0e\u6587\u672c\u6a21\u5f0f\u5339\u914d\u7684\u6240\u6709\u7684\u884c\u3002\u672c\u4f8b\u4e2d\uff0c\u6709test\u7684\u884c\u3002\u5168\u90e8\u6539\u53d8\u4e3ahello<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '\/test\/c hello' data4<br \/>\nhello<br \/>\nhello<br \/>\nhello<br \/>\nhello<br \/>\nhello<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b4\uff1a\u4f7f\u7528\u884c\u5730\u5740\u8303\u56f4\uff0c\u4f46\u7ed3\u679c\u53ef\u80fd\u4e0d\u662f\u9884\u671f\u7684\u6548\u679c\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '2,3c this is the changed line' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the changed line<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u6ce8\uff1a\u672c\u4f8b\u4e2d\uff0csed\u7f16\u8f91\u5668\u6ca1\u6709\u7528\u6587\u672c\u66f4\u6539\u4e24\u884c\uff0c\u800c\u662f\u4f7f\u7528\u5355\u4e00\u884c\u6587\u672c\u66ff\u6362\u4e86\u4e24\u884c\u6587\u672c\u3002<\/p>\n<p>\u4e94\uff1a\u53d8\u6362\u547d\u4ee4<\/p>\n<pre><code>  \u53d8\u6362\u547d\u4ee4\uff08y\uff09\u662f\u552f\u4e00\u5bf9\u5355\u4e2a\u5b57\u7b26\u8fdb\u884c\u64cd\u4f5c\u7684sed\u7f16\u8f91\u5668\u547d\u4ee4\u3002\u53d8\u6362\u547d\u4ee4\u4f7f\u7528\u7684\u683c\u5f0f\u4e3a\uff1a<\/code><\/pre>\n<p>[address]y\/inchars\/outchars\/<\/p>\n<p>\u53d8\u6362\u547d\u4ee4\u5c06inchars\u548coutchars\u7684\u503c\u8fdb\u884c\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u5c06inchars\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u8f6c\u6362\u4e3aoutchars\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u3002\u5c06inchars\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u8f6c\u6362\u4e3aoutchars\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u3002\u4ee5\u6b64\u7c7b\u63a8\u3002<\/p>\n<p>\u793a\u4f8b1\uff1a\u4e00\u5bf9\u4e00\u6620\u5c04\u3002\u5c06123\u5206\u522b\u66ff\u6362\u6210789<\/p>\n<p>[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed 'y\/123\/789\/' data4<br \/>\nthis is the a test line and is the 7<br \/>\nthis is the a test line and is the 8<br \/>\nthis is the a test line and is the 9<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u6ce8\uff1a\u53d8\u6362\u547d\u4ee4\u662f\u5168\u5c40\u547d\u4ee4\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u5b83\u81ea\u52a8\u5bf9\u5728\u6587\u672c\u884c\u4e2d\u53d1\u73b0\u7684\u4efb\u610f\u5b57\u7b26\u8fdb\u884c\u53d8\u6362\uff0c\u800c\u4e0d\u7ba1\u5176\u662f\u7b2c\u51e0\u6b21\u51fa\u73b0\u3002\u4e0b\u9762\u4f5c\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<p>\u793a\u4f8b2\uff1a<\/p>\n<p>[root@linuxmoon ~]# echo &quot;the 2 is the test number 2 &quot; |sed 'y\/2\/8\/'<br \/>\nthe 8 is the test number 8<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u516d\uff1a\u6253\u5370\u547d\u4ee4<\/p>\n<pre><code> sed\u7f16\u8f91\u5668\u67093\u4e2a\u547d\u4ee4\u4e5f\u53ef\u4ee5\u7528\u4e8e\u6253\u5370\u6765\u81ea\u6570\u636e\u6d41\u7684\u4fe1\u606f\uff1a<\/code><\/pre>\n<p>\u6253\u5370\u6587\u672c\u884c\u7684\u5c0f\u5199p\u547d\u4ee4<br \/>\n\u6253\u5370\u884c\u53f7\u7684\u7b49\u53f7\uff08=\uff09\u547d\u4ee4<br \/>\n\u5217\u51fa\u884c\u7684l (\u5c0f\u5199L)\u547d\u4ee4<br \/>\n1.\u6253\u5370\u884c<\/p>\n<p>\u4e0e\u66ff\u6362\u547d\u4ee4\u4e2d\u7684p\u6807\u8bb0\u7c7b\u4f3c\uff0cp\u547d\u4ee4\u6253\u5370sed\u7f16\u8f91\u5668\u8f93\u51fa\u4e2d\u7684\u4e00\u884c\uff0c\u5355\u72ec\u4f7f\u7528p\u547d\u4ee4\u6ca1\u6709\u4ec0\u4e48\u6548\u679c\uff1a\u5982\u4e0b\u4f8b\u3002<\/p>\n<p>\u793a\u4f8b1\uff1a<\/p>\n<p>[root@linuxmoon ~]# echo &quot;test line&quot; |sed 'p'<br \/>\ntest line<br \/>\ntest line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u5b83\u6240\u505a\u7684\u53ea\u662f\u6253\u5370\u5df2\u77e5\u7684\u6587\u672c\u3002\u6253\u5370\u547d\u4ee4\u6700\u5e38\u7528\u7684\u662f\u6253\u5370\u5305\u542b\u5339\u914d\u6a21\u5f0f\u7684\u884c\u3002\u5982\u4e0b\u4f8b\u3002<\/p>\n<p>\u793a\u4f8b2\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# sed -n '\/not\/p' data5   #\u4f7f\u7528-n \u9009\u9879\uff0c\u53ea\u6253\u5370\u5305\u542b\u5339\u914d\u6a21\u5f0f\u7684\u884c<br \/>\nthis is not the test line<br \/>\n[root@linuxmoon ~]# sed '\/not\/p' data5       #\u6ca1\u6709\u4f7f\u7528-n\u9009\u9879\uff0c\u628a\u6240\u6709\u7684\u884c\u90fd\u6253\u5370\u51fa\u6765\u4e86\uff0c\u5305\u62ec\u672a\u5339\u914d\u7684\u884c<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b3\uff1a\u6253\u5370\u884c\u53f7\u7684\u53e6\u4e00\u4e2a\u7528\u9014\u662f\u6539\u53d8\u67d0\u884c\u524d\u67e5\u770b\u8be5\u884c\u3002\u5982\u5229\u7528\u66ff\u6362\u6216\u66f4\u6539\u547d\u4ee4\uff0c\u53ef\u4ee5\u521b\u5efa\u811a\u672c\u5728\u4e00\u884c\u66f4\u6539\u4e4b\u524d\u663e\u793a\u8be5\u884c\u3002\u5982\u4e0b\u4f8b\uff1a<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# sed -n '\/not\/{<\/p>\n<blockquote>\n<p>p<br \/>\ns\/not\/hello\/p<br \/>\n}' data5<br \/>\nthis is not the test line<br \/>\nthis is hello the test line<br \/>\n[root@linuxmoon ~]#<\/p>\n<\/blockquote>\n<p>\u672c\u4f8b\u5148\u67e5\u770b\u542b\u6709not\u7684\u884c\u3002\u7136\u540e\u628a\u6b64\u884c\u7684not \u66f4\u6362\u4e3ahello\uff0c\u5e76\u4e14\u6253\u5370\u51fa\u6765\u3002<\/p>\n<p>2.\u6253\u5370\u884c\u53f7<\/p>\n<p>\u7b49\u53f7\u547d\u4ee4\u6253\u5370\u6570\u636e\u6d41\u5185\u7684\u5f53\u524d\u884c\u7684\u884c\u53f7\u3002<\/p>\n<p>\u793a\u4f8b1\uff1a\u6253\u5370\u884c\u53f7<\/p>\n<p>[root@linuxmoon ~]# sed '=' data5<br \/>\n1<br \/>\nthis is the test line<br \/>\n2<br \/>\nthis is not the test line<br \/>\n3<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b2\uff1a\u6253\u5370\u5339\u914d\u7684\u884c\u4ee5\u53ca\u884c\u53f7<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# sed -n '\/not\/{<\/p>\n<blockquote>\n<p>=<br \/>\np<br \/>\n}' data5<br \/>\n2<br \/>\nthis is not the test line<br \/>\n[root@linuxmoon ~]#<\/p>\n<\/blockquote>\n<p>\u4e03\uff1a\u5c06\u6587\u4ef6\u7528\u4e8esed<\/p>\n<pre><code> \u66ff\u6362\u547d\u4ee4\u5305\u542b\u5141\u8bb8\u4f60\u5904\u7406\u6587\u4ef6\u7684\u6807\u8bb0\u3002\u4e5f\u6709\u6b63\u89c4\u7684sed\u7f16\u8f91\u5668\u547d\u4ee4\u5141\u8bb8\u4f60\u5904\u7406\u6587\u4ef6\u800c\u4e0d\u5fc5\u66ff\u6362\u6587\u672c\u3002<\/code><\/pre>\n<p>1.\u5199\u6587\u4ef6<\/p>\n<pre><code> w \u547d\u4ee4\u7528\u4e8e\u5c06\u6587\u672c\u884c\u5199\u5165\u6587\u4ef6\u3002\u4f7f\u7528\u683c\u5f0f\u4e3a\uff1a\n\n[address]w filename<\/code><\/pre>\n<p>filename\u53ef\u4ee5\u6307\u5b9a\u4e3a\u76f8\u5bf9\u8def\u5f84\u6216\u7edd\u5bf9\u8def\u5f84\uff0c\u4f46\u5728\u4efb\u610f\u4e00\u79cd\u60c5\u51b5\u4e0b\uff0c\u8fd0\u884csed\u7f16\u8f91\u5668\u7684\u7528\u6237\u5fc5\u987b\u5bf9\u8be5\u6587\u4ef6\u6709\u5199\u6743\u9650\uff0c\u5730\u5740\u53ef\u4ee5\u4f7f\u7528sed\u4e2d\u4efb\u610f\u7c7b\u578b\u7684\u5bfb\u5740\u65b9\u6cd5\u3002<\/p>\n<p>\u793a\u4f8b1\uff1a\u5c06\u6570\u636e\u6d41\u7684\u524d\u4e24\u884c\u5199\u5165\u6587\u4ef6test\u4e2d\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# sed '1,2w test' data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# cat test<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b2\uff1a\u5982\u4e0a\u4f8b\uff0c\u5982\u679c\u4e0d\u60f3\u5728stdout\u4e0a\u663e\u793a\u51fa\u6765\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528 \u2013n \u9009\u9879<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# sed -n '2,3w test' data5<br \/>\n[root@linuxmoon ~]# cat test<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b3\uff1a\u6587\u672c\u5339\u914d\u6a21\u5f0f\u3002\u672c\u4f8b\u4ec5\u628a\u5339\u914d\u7684\u884c\u5199\u5165test\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# sed -n '\/not\/w test' data5<br \/>\n[root@linuxmoon ~]# cat test<br \/>\nthis is not the test line<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>2.\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u3002<\/p>\n<p>\u524d\u9762\u4ecb\u7ecd\u4e86\u5411\u6570\u636e\u6d41\u4e2d\u63d2\u5165\u6216\u9644\u52a0\u6587\u672c\u7684\u65b9\u6cd5\u3002\u8bfb\u547d\u4ee4\uff08r\uff09\u5141\u8bb8\u4f60\u63d2\u5165\u5305\u542b\u5728\u72ec\u7acb\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<p>\u8bfb\u547d\u4ee4\u7684\u683c\u5f0f\u4e3a   [address]r filename<\/p>\n<p>filename\u53c2\u6570\u53ef\u4ee5\u4e3a\u7edd\u5bf9\u8def\u5f84\u4e5f\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u3002\u5bf9\u4e8e\u8bfb\u547d\u4ee4\uff0c\u4e0d\u80fd\u4f7f\u7528\u5730\u5740\u8303\u56f4\u3002\u53ea\u80fd\u6307\u5b9a\u5355\u4e00\u7684\u884c\u53f7\u6216\u6587\u672c\u6a21\u5f0f\u3002sed\u7f16\u8f91\u5668\u5728\u8be5\u5730\u5740\u4e4b\u540e\u63d2\u5165\u6587\u4ef6\u4e2d\u7684\u6587\u672c\u3002<\/p>\n<p>\u793a\u4f8b1\uff1a\u4f7f\u7528\u884c\u53f7\u3002\u672c\u4f8b\u4e2d\u628a\u6587\u4ef6data5\u4e2d\u7684\u5185\u5bb9\u63d2\u5165\u5230\u6587\u4ef6data4\u7684\u7b2c3\u884c\u4e4b\u540e\u3002<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '3r data5' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u793a\u4f8b2\uff1a\u4f7f\u7528\u6587\u672c\u6a21\u5f0f<\/p>\n<p>[root@linuxmoon ~]# cat data5<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\n[root@linuxmoon ~]# cat data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]# sed '\/the 2\/r data5' data4<br \/>\nthis is the a test line and is the 1<br \/>\nthis is the a test line and is the 2<br \/>\nthis is the test line<br \/>\nthis is not the test line<br \/>\nthis is the new line<br \/>\nthis is the a test line and is the 3<br \/>\nthis is the a test line and is the 4<br \/>\nthis is the a test line and is the 5<br \/>\n[root@linuxmoon ~]#<\/p>\n<p>\u5c0f\u7ed3\uff1a\u5c3d\u7ba1shell\u53ef\u4ee5\u5b8c\u6210\u5f88\u591a\u7684\u5de5\u4f5c\uff0c\u4f46\u4ec5\u4ec5\u4f1ashell\u811a\u672c\u8fd8\u662f\u5f88\u96be\u5904\u7406\u6570\u636e\u3002linux\u63d0\u4f9b\u4e86\u4e24\u4e2a\u5f3a\u5927\u7684\u7684\u5b9e\u7528\u5de5\u5177\u6765\u8f85\u52a9\u5904\u7406\u6587\u672c\u6570\u636e\u3002sed\u7f16\u8f91\u5668\u662f\u80fd\u591f\u5728\u8bfb\u53d6<\/p>\n<p>\u6570\u636e\u65f6\u52a8\u6001\u5904\u7406\u6570\u636e\u3002<\/p>\n<p>gawk\u7a0b\u5e8f\u662f\u6765\u81eaGNU\u7ec4\u7ec7\u7684\u4e00\u4e2a\u5b9e\u7528\u7a0b\u5e8f\uff0c\u5b83\u80fd\u591f\u6a21\u62df\u548c\u6269\u5c55Unix shell\u7684awk\u7a0b\u5e8f\u7684\u529f\u80fd\u3002<\/p>\n<p>sed\u548cawk\u7a0b\u5e8f\u7684\u81f3\u5173\u91cd\u8981\u7684\u4e00\u70b9\u662f\u53ef\u4ee5\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u662f\u521b\u5efa\u81ea\u5b9a\u4e49\u7b5b\u9009\u5668\u62bd\u53d6\u548c\u5904\u7406\u6587\u672c\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u7684\u5173\u952e\u3002<\/p>\n<p>\u5982\u679c\u8fd8\u8981\u66f4\u597d\u7684\u5904\u7406linux\u65e5\u5e38\u7684\u4efb\u52a1\uff0c\u6700\u597d\u8fd8\u8981\u5b66\u4e00\u95e8\u5176\u5b83\u7684\u811a\u672c\u8bed\u8a00\uff0c\u6bd4\u5982\u6709\u65f6\u5019\u53ef\u4ee5\u81ea\u5df1\u5f00\u53d1\u4e00\u4e9b\u5c0f\u5de5\u5177\uff0c\u4e2a\u4eba\u63a8\u8350perl,python<\/p>\n<p>\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\u7684\u6307\u5b9a\u884c \u7279\u6b8a\u65b9\u6cd5 <\/p>\n<ol>\n<li>\u5982\u679c\u4f60\u53ea\u60f3\u770b\u6587\u4ef6\u7684\u524d5\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528head\u547d\u4ee4\uff0c\u5982\uff1a<br \/>\nhead -5 \/etc\/passwd<\/li>\n<li>\u5982\u679c\u4f60\u60f3\u67e5\u770b\u6587\u4ef6\u7684\u540e10\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528tail\u547d\u4ee4\uff0c\u5982\uff1a<br \/>\ntail -10 \/etc\/passwd<br \/>\ntail -f \/var\/log\/messages<br \/>\n\u53c2\u6570-f\u4f7ftail\u4e0d\u505c\u5730\u53bb\u8bfb\u6700\u65b0\u7684\u5185\u5bb9\uff0c\u8fd9\u6837\u6709\u5b9e\u65f6\u76d1\u89c6\u7684\u6548\u679c\uff0c\u5f53\u4f60\u5728ppp\u62e8\u53f7\u7684\u8fc7\u7a0b\u4e2d\u7528\u5b83\u5c82\u4e0d\u662f\u5f88\u65b9\u4fbf\uff01<\/li>\n<li>\u67e5\u770b\u6587\u4ef6\u4e2d\u95f4\u4e00\u6bb5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528sed\u547d\u4ee4\uff0c\u5982\uff1a<br \/>\nsed -n '5,10p' \/etc\/passwd<br \/>\n\u8fd9\u6837\u4f60\u5c31\u53ef\u4ee5\u53ea\u67e5\u770b\u6587\u4ef6\u7684\u7b2c5\u884c\u5230\u7b2c10\u884c<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Linux\u4e0a\u5de5\u4f5c,\u9700\u8981\u52a8\u6001\u7684\u5904\u7406\u6587\u672c,\u800c\u4e0d\u5fc5\u4f7f\u7528\u5b8c\u5907\u7684\u6587\u672c\u7f16\u8f91\u5668,\u5728\u8fd9\u6837\u60c5\u51b5\u4e00\u4e0a\uff0c\u62e5\u6709\u4e00\u4e2a\u80fd\u591f\u65b9\u4fbf\u5730\u683c\u5f0f\u5316\uff0c\u63d2\u5165\uff0c\u4fee\u6539\uff0c\u5220\u9664\uff0c\u6587\u672c\u7684\u7b80\u5355\u547d\u4ee4\u884c\u7f16\u8f91\u5668\u5c31\u5f88\u6709\u7528\u4e86\u3002 linux\u4e0a\u6700\u5e38\u7528\u7684\u4e24\u4e2a\u6d41\u7f16\u8f91\u5668sed\u548cawk\u5c31\u662f\u8fd9\u6837\u7684\u5de5\u5177\u3002\u672c\u6587\u4e3b\u8981\u8ba8\u8bbased\u7684\u7528\u6cd5\u3002 sed\u7f16\u8f91\u5668\u79f0\u4e3a\u6d41\u7f16\u8f91\u5668\uff0c\u5b83\u6bcf\u6b21\u53ea\u5904\u7406\u4e00\u884c\u6570\u636e\uff0c\u5c06\u8be5\u6570\u636e\u4e0e\u6240\u63d0\u4f9b\u7684\u7f16\u8f91\u5668\u547d\u4ee4\u8fdb\u884c\u5339\u914d\uff0c\u6839\u636e\u547d\u4ee4\u4fee\u6539\u6570\u636e\u6d41\u4e2d\u7684\u6570\u636e\uff0c\u7136\u540e\u5c06\u65b0\u6570\u636e\u8f93\u51fa\u5230stdout\u4e0a\uff0c\u4e4b\u540e\u5b83\u5c06\u8bfb\u53d6\u4e0b\u4e00\u884c\u6570\u636e\uff0c\u5e76\u91cd\u590d\u4e0a\u8ff0\u7684\u52a8\u4f5c\u3002\u5904\u7406\u5b8c\u6d41\u6570\u636e\u4e2d\u7684\u5168\u90e8\u6570\u636e\u4e4b\u540e\uff0c\u6d41\u7f16\u8f91\u5668\u505c\u6b62\u3002 sed\u547d\u4ee4\u4e0d\u4fee\u6539\u539f\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u53ea\u662f\u5c06\u4fee\u6539\u7684\u7ed3\u679c\u663e\u793a\u51fa\u6765\u800c\u5df2\uff0c\u539f\u6587\u4ef6\u4e0d\u4f1a\u6539\u53d8\u3002 sed\u7684\u547d\u4ee4\u683c\u5f0f\u662f\uff1a sed options scripts file options\u53c2\u6570\u5141\u8bb8\u81ea\u5b9a\u4e49sed\u7684\u547d\u4ee4\u884c\u4e3a\uff0c\u5b83\u5305\u542b\u7684\u9009\u9879\u5982\u4e0b\uff1a \u9009\u9879 \u63cf\u8ff0 -e scripts \u5c06\u811a\u672c\u4e2d\u6307\u5b9a\u7684\u547d\u4ee4\u6dfb\u52a0\u5230\u5904\u7406\u8f93\u5165\u65f6\u6267\u884c\u7684\u547d\u4ee4\u4e2d -f file \u5c06\u6587\u4ef6\u4e2d\u6307\u5b9a\u7684\u547d\u4ee4\u6dfb\u52a0\u5230\u5904\u7406\u8f93\u5165\u65f6\u6267\u884c\u7684\u547d\u4ee4 -n \u4e0d\u9700\u8981\u4e3a\u6bcf\u4e2a\u547d\u4ee4\u4ea7\u751f\u8f93\u51fa\uff0c\u4f46\u8981\u7b49\u5f85\u6253\u5370\u547d\u4ee4\uff0c\u7ecf\u5e38\u548c-p \u4e00\u8d77\u4f7f\u7528 scripts\u53c2\u6570\u6307\u5b9a\u8981\u5e94\u7528\u4e8e\u6d41\u6570\u636e\u7684\u5355\u4e2a\u547d\u4ee4\u3002\u5982\u679c\u9700\u8981\u591a\u4e2a\u547d\u4ee4\uff0c\u5c31\u5fc5\u987b\u4f7f\u7528 -e \u547d\u4ee4\uff0c \u6216\u8005\u4f7f\u7528-f \u9009\u9879\u5728\u5355\u72ec\u7684\u6587\u4ef6\u4e2d\u6307\u5b9a\u3002 \u4e00\uff1a\u5728\u547d\u4ee4\u884c\u4e2d\u5b9a\u4e49\u7f16\u8f91\u5668\u547d\u4ee4\u3002 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0csed\u7f16\u8f91\u5668\u5c06\u6307\u5b9a\u7684\u547d\u4ee4\u5e94\u7528\u4e8eSTDIN\u8f93\u5165\u6d41\u3002\u8fd9\u5c31\u5141\u8bb8\u5c06\u6570\u636e\u901a\u8fc7\u7ba1\u9053\u4f20\u9001\u7ed9sed\u7f16\u8f91\u5668\u8fdb\u884c\u5904\u7406\u3002 \u5982\u4e0b\u9762\u7684\u4e00\u4e2a\u4f8b\u5b50\u3002\u672c\u6587\u6240\u4ee5\u7684\u4f8b\u5b50\u90fd\u5728root\u7684\u5bb6\u76ee\u5f55\u4e0b\u8fdb\u884c\u7684\u3002 [root@linuxmoon ~]# echo &quot;this is a test page&quot; | sed &#8216;s\/page\/home\/&#8217; this is a test home \u8be5\u4f8bsed\u4f7f\u7528\u4e86 s \u547d\u4ee4\u3002s \u7528\u4e8e\u5c06\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u66ff\u6362\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u672c\u4f8bhome\u66ff\u6362page \u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u4e5f\u53ef\u4ee5\u6709\u7a7a\u683c\u3002\u5982\u4e0bred apple\u66ff\u6362apple [root@linuxmoon ~]# echo &quot;this is an big apple&quot; | sed &#8216;s\/apple\/red apple\/&#8217; this is an big red apple \u4e5f\u53ef\u4ee5\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5e76\u5904\u7406\uff0c\u4f46\u539f\u6587\u4ef6\u4e0d\u4f1a\u4fee\u6539\u3002\u5982\u4e0b\uff1a [root@linuxmoon ~]# cat data1 this is an big apple this is an big red apple this is an small apple this ia an small red apple this is no an apple [root@linuxmoon ~]# sed &#8216;s\/apple\/bird\/&#8217; data1 this is an big bird this is an big red bird this is an small bird this ia an small red bird this is no an bird \u67e5\u770b\u539f\u6587\u4ef6\uff0c\u4ecd\u7136\u662f\u539f\u6765\u7684\u6570\u636e [root@linuxmoon ~]# cat data1 this is an big apple this is an big red apple this is an small apple this ia an small red apple this is no an apple [root@linuxmoon ~]# \u672c\u4f8b\u4e2d\u628a\u6587\u4ef6data1\u4e2d\u7684\u6240\u6709\u7684apple\u5c31\u66ff\u6362\u6210\u4e86bird 2.\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u591a\u4e2a\u547d\u4ee4 [root@linuxmoon ~]# cat data1 this is an big apple this is an big red apple this is an small apple this ia an small red apple this is no an apple [root@linuxmoon ~]# sed -e &#8216;s\/big\/very big\/;s\/small\/very small\/&#8217; data1 this is an very big apple this is an very big red apple this is an very small apple this ia an very small red apple this is no an apple [root@linuxmoon ~]# \u4e24\u4e2a\u547d\u4ee4\u5c06\u540c\u65f6\u4f5c\u7528\u4e8e\u6587\u4ef6\u4e2d\u7684\u6bcf\u4e00\u884c\u6570\u636e\u3002\u547d\u4ee4\u5fc5\u987b\u7528\u5206\u53f7\u9694\u5f00\uff0c\u4e14\u5728\u547d\u4ee4\u7ed3\u5c3e\u548c\u5206\u53f7\u4e4b\u95f4\u4e0d\u80fd\u6709\u7a7a\u683c\u3002 \u4e5f\u53ef\u4ee5\u7528\u547d\u63d0\u793a\u7b26\uff0c\u5982\u4e0b\uff1a root@linuxmoon ~]# cat data1 this is an big apple this is an big red apple this is an small a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","footnotes":""},"categories":[87,82],"tags":[],"class_list":["post-1691","post","type-post","status-publish","format-standard","hentry","category-linux","category-82"],"_links":{"self":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1691"}],"version-history":[{"count":1,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1691\/revisions"}],"predecessor-version":[{"id":1692,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/1691\/revisions\/1692"}],"wp:attachment":[{"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1691"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/oneai.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}