{"id":75221,"date":"2023-08-14T21:51:15","date_gmt":"2023-08-14T13:51:15","guid":{"rendered":"http:\/\/lrxjmw.cn\/?p=75221"},"modified":"2023-08-14T21:51:15","modified_gmt":"2023-08-14T13:51:15","slug":"linux-sed-command","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-sed-command.html","title":{"rendered":"Linux\u4e4bsed\u547d\u4ee4\u8be6\u89e3"},"content":{"rendered":"
sed<\/strong>\u662f\u4e00\u79cd\u6d41\u7f16\u8f91\u5668\uff0c\u5b83\u662f\u6587\u672c\u5904\u7406\u4e2d\u975e\u5e38\u597d\u7684\u5de5\u5177\uff0c\u80fd\u591f\u5b8c\u7f8e\u7684\u914d\u5408\u6b63\u5219\u8868\u8fbe\u5f0f\u4f7f\u7528\uff0c\u529f\u80fd\u4e0d\u540c\u51e1\u54cd\u3002\u5904\u7406\u65f6\uff0c\u628a\u5f53\u524d\u5904\u7406\u7684\u884c\u5b58\u50a8\u5728\u4e34\u65f6\u7f13\u51b2\u533a\u4e2d\uff0c\u79f0\u4e3a\u201c\u6a21\u5f0f\u7a7a\u95f4\u201d\uff08pattern space\uff09\uff0c\u63a5\u7740\u7528sed\u547d\u4ee4\u5904\u7406\u7f13\u51b2\u533a\u4e2d\u7684\u5185\u5bb9\uff0c\u5904\u7406\u5b8c\u6210\u540e\uff0c\u628a\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u9001\u5f80\u5c4f\u5e55\u3002\u63a5\u7740\u5904\u7406\u4e0b\u4e00\u884c\uff0c\u8fd9\u6837\u4e0d\u65ad\u91cd\u590d\uff0c\u76f4\u5230\u6587\u4ef6\u672b\u5c3e\u3002\u6587\u4ef6\u5185\u5bb9\u5e76\u6ca1\u6709\u6539\u53d8\uff0c\u9664\u975e\u4f60\u4f7f\u7528\u91cd\u5b9a\u5411\u5b58\u50a8\u8f93\u51fa\u3002Sed\u4e3b\u8981\u7528\u6765\u81ea\u52a8\u7f16\u8f91\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6\uff0c\u53ef\u4ee5\u5c06\u6570\u636e\u884c\u8fdb\u884c\u66ff\u6362\u3001\u5220\u9664\u3001\u65b0\u589e\u3001\u9009\u53d6\u7b49\u7279\u5b9a\u5de5\u4f5c\uff0c\u7b80\u5316\u5bf9\u6587\u4ef6\u7684\u53cd\u590d\u64cd\u4f5c\uff0c\u7f16\u5199\u8f6c\u6362\u7a0b\u5e8f\u7b49\u3002<\/p>\n \u547d\u4ee4\u683c\u5f0f<\/strong><\/p>\n \u9009\u9879<\/strong><\/p>\n \u53c2\u6570<\/strong><\/p>\n \u6587\u4ef6\uff1a\u6307\u5b9a\u5f85\u5904\u7406\u7684\u6587\u672c\u6587\u4ef6\u5217\u8868\u3002<\/p>\n sed\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n sed\u66ff\u6362\u6807\u8bb0<\/strong><\/p>\n sed\u5143\u5b57\u7b26\u96c6<\/strong><\/p>\n \u66ff\u6362\u64cd\u4f5c\uff1as\u547d\u4ee4<\/strong><\/p>\n \u66ff\u6362\u6587\u672c\u4e2d\u7684\u5b57\u7b26\u4e32\uff1a <\/p>\n -n\u9009\u9879<\/strong>\u548cp\u547d\u4ee4<\/strong>\u4e00\u8d77\u4f7f\u7528\u8868\u793a\u53ea\u6253\u5370\u90a3\u4e9b\u53d1\u751f\u66ff\u6362\u7684\u884c\uff1a <\/p>\n \u76f4\u63a5\u7f16\u8f91\u6587\u4ef6\u9009\u9879-i<\/strong>\uff0c\u4f1a\u5339\u914dfile\u6587\u4ef6\u4e2d\u6bcf\u4e00\u884c\u7684\u7b2c\u4e00\u4e2abook\u66ff\u6362\u4e3abooks<\/p>\n \u5168\u9762\u66ff\u6362\u6807\u8bb0g<\/strong><\/p>\n \u4f7f\u7528\u540e\u7f00 \/g \u6807\u8bb0\u4f1a\u66ff\u6362\u6bcf\u4e00\u884c\u4e2d\u7684\u6240\u6709\u5339\u914d\uff1a<\/p>\n \u5f53\u9700\u8981\u4ece\u7b2cN\u5904\u5339\u914d\u5f00\u59cb\u66ff\u6362\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 \/Ng\uff1a<\/p>\n \u5b9a\u754c\u7b26<\/strong><\/p>\n \u4ee5\u4e0a\u547d\u4ee4\u4e2d\u5b57\u7b26 \/ \u5728sed\u4e2d\u4f5c\u4e3a\u5b9a\u754c\u7b26\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u4efb\u610f\u7684\u5b9a\u754c\u7b26<\/p>\n \u5b9a\u754c\u7b26\u51fa\u73b0\u5728\u6837\u5f0f\u5185\u90e8\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u8f6c\u4e49\uff1a<\/p>\n \u5220\u9664\u64cd\u4f5c\uff1ad\u547d\u4ee4<\/strong><\/p>\n \u5220\u9664\u7a7a\u767d\u884c\uff1a<\/p>\n \u5220\u9664\u6587\u4ef6\u7684\u7b2c2\u884c\uff1a<\/p>\n \u5220\u9664\u6587\u4ef6\u7684\u7b2c2\u884c\u5230\u672b\u5c3e\u6240\u6709\u884c\uff1a <\/p>\n \u5220\u9664\u6587\u4ef6\u6700\u540e\u4e00\u884c\uff1a<\/p>\n \u5220\u9664\u6587\u4ef6\u4e2d\u6240\u6709\u5f00\u5934\u662ftest\u7684\u884c\uff1a<\/p>\n \u5df2\u5339\u914d\u5b57\u7b26\u4e32\u6807\u8bb0&<\/strong><\/p>\n \u6b63\u5219\u8868\u8fbe\u5f0f \\w\\+ \u5339\u914d\u6bcf\u4e00\u4e2a\u5355\u8bcd\uff0c\u4f7f\u7528 [&] \u66ff\u6362\u5b83\uff0c& \u5bf9\u5e94\u4e8e\u4e4b\u524d\u6240\u5339\u914d\u5230\u7684\u5355\u8bcd\uff1a<\/p>\n \u6240\u6709\u4ee5192.168.0.1\u5f00\u5934\u7684\u884c\u90fd\u4f1a\u88ab\u66ff\u6362\u6210\u5b83\u81ea\u5df2\u52a0localhost\uff1a <\/p>\n \u5b50\u4e32\u5339\u914d\u6807\u8bb0\\1<\/strong> <\/p>\n \u5339\u914d\u7ed9\u5b9a\u6837\u5f0f\u7684\u5176\u4e2d\u4e00\u90e8\u5206\uff1a<\/p>\n \u547d\u4ee4\u4e2d digit 7\uff0c\u88ab\u66ff\u6362\u6210\u4e86 7\u3002\u6837\u5f0f\u5339\u914d\u5230\u7684\u5b50\u4e32\u662f 7\uff0c\\(..\\) \u7528\u4e8e\u5339\u914d\u5b50\u4e32\uff0c\u5bf9\u4e8e\u5339\u914d\u5230\u7684\u7b2c\u4e00\u4e2a\u5b50\u4e32\u5c31\u6807\u8bb0\u4e3a \\1\uff0c\u4f9d\u6b64\u7c7b\u63a8\u5339\u914d\u5230\u7684\u7b2c\u4e8c\u4e2a\u7ed3\u679c\u5c31\u662f \\2\uff0c\u4f8b\u5982\uff1a <\/p>\n love\u88ab\u6807\u8bb0\u4e3a1\uff0c\u6240\u6709loveable\u4f1a\u88ab\u66ff\u6362\u6210lovers\uff0c\u5e76\u6253\u5370\u51fa\u6765\uff1a <\/p>\n \u7ec4\u5408\u591a\u4e2a\u8868\u8fbe\u5f0f<\/strong><\/p>\n \u5f15\u7528<\/strong><\/p>\n sed\u8868\u8fbe\u5f0f\u53ef\u4ee5\u4f7f\u7528\u5355\u5f15\u53f7\u6765\u5f15\u7528\uff0c\u4f46\u662f\u5982\u679c\u8868\u8fbe\u5f0f\u5185\u90e8\u5305\u542b\u53d8\u91cf\u5b57\u7b26\u4e32\uff0c\u5c31\u9700\u8981\u4f7f\u7528\u53cc\u5f15\u53f7\u3002 <\/p>\n \u9009\u5b9a\u884c\u7684\u8303\u56f4\uff1a,\uff08\u9017\u53f7\uff09<\/strong> <\/p>\n \u6240\u6709\u5728\u6a21\u677ftest\u548ccheck\u6240\u786e\u5b9a\u7684\u8303\u56f4\u5185\u7684\u884c\u90fd\u88ab\u6253\u5370\uff1a <\/p>\n \u6253\u5370\u4ece\u7b2c5\u884c\u5f00\u59cb\u5230\u7b2c\u4e00\u4e2a\u5305\u542b\u4ee5test\u5f00\u59cb\u7684\u884c\u4e4b\u95f4\u7684\u6240\u6709\u884c\uff1a <\/p>\n \u5bf9\u4e8e\u6a21\u677ftest\u548cwest\u4e4b\u95f4\u7684\u884c\uff0c\u6bcf\u884c\u7684\u672b\u5c3e\u7528\u5b57\u7b26\u4e32aaa bbb\u66ff\u6362\uff1a <\/p>\n \u591a\u70b9\u7f16\u8f91\uff1ae\u547d\u4ee4<\/strong><\/p>\n -e\u9009\u9879\u5141\u8bb8\u5728\u540c\u4e00\u884c\u91cc\u6267\u884c\u591a\u6761\u547d\u4ee4\uff1a <\/p>\n \u4e0a\u9762sed\u8868\u8fbe\u5f0f\u7684\u7b2c\u4e00\u6761\u547d\u4ee4\u5220\u96641\u81f35\u884c\uff0c\u7b2c\u4e8c\u6761\u547d\u4ee4\u7528check\u66ff\u6362test\u3002\u547d\u4ee4\u7684\u6267\u884c\u987a\u5e8f\u5bf9\u7ed3\u679c\u6709\u5f71\u54cd\u3002\u5982\u679c\u4e24\u4e2a\u547d\u4ee4\u90fd\u662f\u66ff\u6362\u547d\u4ee4\uff0c\u90a3\u4e48\u7b2c\u4e00\u4e2a\u66ff\u6362\u547d\u4ee4\u5c06\u5f71\u54cd\u7b2c\u4e8c\u4e2a\u66ff\u6362\u547d\u4ee4\u7684\u7ed3\u679c\u3002 <\/p>\n \u548c -e \u7b49\u4ef7\u7684\u547d\u4ee4\u662f --expression\uff1a <\/p>\n \u4ece\u6587\u4ef6\u8bfb\u5165\uff1ar\u547d\u4ee4<\/strong><\/p>\n file\u91cc\u7684\u5185\u5bb9\u88ab\u8bfb\u8fdb\u6765\uff0c\u663e\u793a\u5728\u4e0etest\u5339\u914d\u7684\u884c\u540e\u9762\uff0c\u5982\u679c\u5339\u914d\u591a\u884c\uff0c\u5219file\u7684\u5185\u5bb9\u5c06\u663e\u793a\u5728\u6240\u6709\u5339\u914d\u884c\u7684\u4e0b\u9762\uff1a <\/p>\n \u5199\u5165\u6587\u4ef6\uff1aw\u547d\u4ee4<\/strong> \u8ffd\u52a0\uff08\u884c\u4e0b\uff09\uff1aa\\\u547d\u4ee4<\/strong><\/p>\n \u5c06 this is a test line \u8ffd\u52a0\u5230 \u4ee5test \u5f00\u5934\u7684\u884c\u540e\u9762\uff1a <\/p>\n \u5728 test.conf \u6587\u4ef6\u7b2c2\u884c\u4e4b\u540e\u63d2\u5165 this is a test line\uff1a <\/p>\n \u63d2\u5165\uff08\u884c\u4e0a\uff09\uff1a<\/strong><\/p>\n i\\\u547d\u4ee4 \u5c06 this is a test line \u8ffd\u52a0\u5230\u4ee5test\u5f00\u5934\u7684\u884c\u524d\u9762\uff1a <\/p>\n \u5728test.conf\u6587\u4ef6\u7b2c5\u884c\u4e4b\u524d\u63d2\u5165this is a test line\uff1a <\/p>\n \u4e0b\u4e00\u4e2a\uff1an\u547d\u4ee4 <\/strong><\/p>\n \u5982\u679ctest\u88ab\u5339\u914d\uff0c\u5219\u79fb\u52a8\u5230\u5339\u914d\u884c\u7684\u4e0b\u4e00\u884c\uff0c\u66ff\u6362\u8fd9\u4e00\u884c\u7684aa\uff0c\u53d8\u4e3abb\uff0c\u5e76\u6253\u5370\u8be5\u884c\uff0c\u7136\u540e\u7ee7\u7eed\uff1a <\/p>\n \u53d8\u5f62\uff1ay\u547d\u4ee4 <\/strong><\/p>\n \u628a1~10\u884c\u5185\u6240\u6709abcde\u8f6c\u53d8\u4e3a\u5927\u5199\uff0c\u6ce8\u610f\uff0c\u6b63\u5219\u8868\u8fbe\u5f0f\u5143\u5b57\u7b26\u4e0d\u80fd\u4f7f\u7528\u8fd9\u4e2a\u547d\u4ee4\uff1a <\/p>\n \u9000\u51fa\uff1aq\u547d\u4ee4 <\/strong><\/p>\n \u6253\u5370\u5b8c\u7b2c10\u884c\u540e\uff0c\u9000\u51fased sed '10q' file \u4fdd\u6301\u548c\u83b7\u53d6\uff1ah\u547d\u4ee4\u548cG\u547d\u4ee4 \u5728sed\u5904\u7406\u6587\u4ef6\u7684\u65f6\u5019\uff0c\u6bcf\u4e00\u884c\u90fd\u88ab\u4fdd\u5b58\u5728\u4e00\u4e2a\u53eb\u6a21\u5f0f\u7a7a\u95f4\u7684\u4e34\u65f6\u7f13\u51b2\u533a\u4e2d\uff0c\u9664\u975e\u884c\u88ab\u5220\u9664\u6216\u8005\u8f93\u51fa\u88ab\u53d6\u6d88\uff0c\u5426\u5219\u6240\u6709\u88ab\u5904\u7406\u7684\u884c\u90fd\u5c06\u6253\u5370\u5728\u5c4f\u5e55\u4e0a\u3002\u63a5\u7740\u6a21\u5f0f\u7a7a\u95f4\u88ab\u6e05\u7a7a\uff0c\u5e76\u5b58\u5165\u65b0\u7684\u4e00\u884c\u7b49\u5f85\u5904\u7406\u3002 <\/p>\n \u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc\uff0c\u5339\u914dtest\u7684\u884c\u88ab\u627e\u5230\u540e\uff0c\u5c06\u5b58\u5165\u6a21\u5f0f\u7a7a\u95f4\uff0ch\u547d\u4ee4\u5c06\u5176\u590d\u5236\u5e76\u5b58\u5165\u4e00\u4e2a\u79f0\u4e3a\u4fdd\u6301\u7f13\u5b58\u533a\u7684\u7279\u6b8a\u7f13\u51b2\u533a\u5185\u3002\u7b2c\u4e8c\u6761\u8bed\u53e5\u7684\u610f\u601d\u662f\uff0c\u5f53\u5230\u8fbe\u6700\u540e\u4e00\u884c\u540e\uff0cG\u547d\u4ee4\u53d6\u51fa\u4fdd\u6301\u7f13\u51b2\u533a\u7684\u884c\uff0c\u7136\u540e\u628a\u5b83\u653e\u56de\u6a21\u5f0f\u7a7a\u95f4\u4e2d\uff0c\u4e14\u8ffd\u52a0\u5230\u73b0\u5728\u5df2\u7ecf\u5b58\u5728\u4e8e\u6a21\u5f0f\u7a7a\u95f4\u4e2d\u7684\u884c\u7684\u672b\u5c3e\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\u5c31\u662f\u8ffd\u52a0\u5230\u6700\u540e\u4e00\u884c\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u4efb\u4f55\u5305\u542btest\u7684\u884c\u90fd\u88ab\u590d\u5236\u5e76\u8ffd\u52a0\u5230\u8be5\u6587\u4ef6\u7684\u672b\u5c3e\u3002<\/p>\n \u4fdd\u6301\u548c\u4e92\u6362\uff1ah\u547d\u4ee4\u548cx\u547d\u4ee4<\/strong><\/p>\n \u4e92\u6362\u6a21\u5f0f\u7a7a\u95f4\u548c\u4fdd\u6301\u7f13\u51b2\u533a\u7684\u5185\u5bb9\u3002\u4e5f\u5c31\u662f\u628a\u5305\u542btest\u4e0echeck\u7684\u884c\u4e92\u6362\uff1a <\/p>\n \u811a\u672cscriptfile <\/strong><\/p>\n sed\u811a\u672c\u662f\u4e00\u4e2ased\u7684\u547d\u4ee4\u6e05\u5355\uff0c\u542f\u52a8Sed\u65f6\u4ee5-f\u9009\u9879\u5f15\u5bfc\u811a\u672c\u6587\u4ef6\u540d\u3002Sed\u5bf9\u4e8e\u811a\u672c\u4e2d\u8f93\u5165\u7684\u547d\u4ee4\u975e\u5e38\u6311\u5254\uff0c\u5728\u547d\u4ee4\u7684\u672b\u5c3e\u4e0d\u80fd\u6709\u4efb\u4f55\u7a7a\u767d\u6216\u6587\u672c\uff0c\u5982\u679c\u5728\u4e00\u884c\u4e2d\u6709\u591a\u4e2a\u547d\u4ee4\uff0c\u8981\u7528\u5206\u53f7\u5206\u9694\u3002\u4ee5#\u5f00\u5934\u7684\u884c\u4e3a\u6ce8\u91ca\u884c\uff0c\u4e14\u4e0d\u80fd\u8de8\u884c\u3002 <\/p>\n \u6253\u5370\u5947\u6570\u884c\u6216\u5076\u6570\u884c <\/strong><\/p>\n \u65b9\u6cd51\uff1a <\/p>\n \u65b9\u6cd52\uff1a <\/p>\n \u6253\u5370\u5339\u914d\u5b57\u7b26\u4e32\u7684\u4e0b\u4e00\u884c<\/strong><\/p>\n \u539f\u6587\u6765\u81ea\uff1ahttp:\/\/man.linuxde.net\/sed<\/a>\n<\/p>\nsed\u7684\u547d\u4ee4\u683c\u5f0f\uff1ased [options] 'command' file(s);
\r\nsed\u7684\u811a\u672c\u683c\u5f0f\uff1ased [options] -f scriptfile file(s);\r\n<\/pre>\n -e \uff1a\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u6a21\u5f0f\u4e0a\u8fdb\u884csed\u52a8\u4f5c\u7f16\u8f91\uff0c\u6b64\u4e3a\u9ed8\u8ba4\u9009\u9879;
\r\n -f \uff1a\u5c06sed\u7684\u52a8\u4f5c\u5199\u5728\u4e00\u4e2a\u6587\u4ef6\u5185\uff0c\u7528\u2013f filename \u6267\u884cfilename\u5185\u7684sed\u52a8\u4f5c;
\r\n -i \uff1a\u76f4\u63a5\u4fee\u6539\u6587\u4ef6\u5185\u5bb9;
\r\n -n \uff1a\u53ea\u6253\u5370\u6a21\u5f0f\u5339\u914d\u7684\u884c\uff1b
\r\n -r \uff1a\u652f\u6301\u6269\u5c55\u8868\u8fbe\u5f0f;
\r\n -h\u6216--help\uff1a\u663e\u793a\u5e2e\u52a9\uff1b
\r\n -V\u6216--version\uff1a\u663e\u793a\u7248\u672c\u4fe1\u606f\u3002\r\n<\/pre>\n\r\n a\\ \u5728\u5f53\u524d\u884c\u4e0b\u9762\u63d2\u5165\u6587\u672c;
\r\n i\\ \u5728\u5f53\u524d\u884c\u4e0a\u9762\u63d2\u5165\u6587\u672c;
\r\n c\\ \u628a\u9009\u5b9a\u7684\u884c\u6539\u4e3a\u65b0\u7684\u6587\u672c;
\r\n d \u5220\u9664\uff0c\u5220\u9664\u9009\u62e9\u7684\u884c;
\r\n D \u5220\u9664\u6a21\u677f\u5757\u7684\u7b2c\u4e00\u884c;
\r\n s \u66ff\u6362\u6307\u5b9a\u5b57\u7b26;
\r\n h \u62f7\u8d1d\u6a21\u677f\u5757\u7684\u5185\u5bb9\u5230\u5185\u5b58\u4e2d\u7684\u7f13\u51b2\u533a;
\r\n H \u8ffd\u52a0\u6a21\u677f\u5757\u7684\u5185\u5bb9\u5230\u5185\u5b58\u4e2d\u7684\u7f13\u51b2\u533a;
\r\n g \u83b7\u5f97\u5185\u5b58\u7f13\u51b2\u533a\u7684\u5185\u5bb9\uff0c\u5e76\u66ff\u4ee3\u5f53\u524d\u6a21\u677f\u5757\u4e2d\u7684\u6587\u672c;
\r\n G \u83b7\u5f97\u5185\u5b58\u7f13\u51b2\u533a\u7684\u5185\u5bb9\uff0c\u5e76\u8ffd\u52a0\u5230\u5f53\u524d\u6a21\u677f\u5757\u6587\u672c\u7684\u540e\u9762;
\r\n l \u5217\u8868\u4e0d\u80fd\u6253\u5370\u5b57\u7b26\u7684\u6e05\u5355;
\r\n n \u8bfb\u53d6\u4e0b\u4e00\u4e2a\u8f93\u5165\u884c\uff0c\u7528\u4e0b\u4e00\u4e2a\u547d\u4ee4\u5904\u7406\u65b0\u7684\u884c\u800c\u4e0d\u662f\u7528\u7b2c\u4e00\u4e2a\u547d\u4ee4;
\r\n N \u8ffd\u52a0\u4e0b\u4e00\u4e2a\u8f93\u5165\u884c\u5230\u6a21\u677f\u5757\u540e\u9762\u5e76\u5728\u4e8c\u8005\u95f4\u5d4c\u5165\u4e00\u4e2a\u65b0\u884c\uff0c\u6539\u53d8\u5f53\u524d\u884c\u53f7\u7801;
\r\n p \u6253\u5370\u6a21\u677f\u5757\u7684\u884c\u3002 P(\u5927\u5199) \u6253\u5370\u6a21\u677f\u5757\u7684\u7b2c\u4e00\u884c;
\r\n q \u9000\u51faSed;
\r\n b lable \u5206\u652f\u5230\u811a\u672c\u4e2d\u5e26\u6709\u6807\u8bb0\u7684\u5730\u65b9\uff0c\u5982\u679c\u5206\u652f\u4e0d\u5b58\u5728\u5219\u5206\u652f\u5230\u811a\u672c\u7684\u672b\u5c3e;
\r\n r file \u4ecefile\u4e2d\u8bfb\u884c;
\r\n t label if\u5206\u652f\uff0c\u4ece\u6700\u540e\u4e00\u884c\u5f00\u59cb\uff0c\u6761\u4ef6\u4e00\u65e6\u6ee1\u8db3\u6216\u8005T\uff0ct\u547d\u4ee4\uff0c\u5c06\u5bfc\u81f4\u5206\u652f\u5230\u5e26\u6709\u6807\u53f7\u7684\u547d\u4ee4\u5904\uff0c\u6216\u8005\u5230\u811a\u672c\u7684\u672b\u5c3e;
\r\n T label \u9519\u8bef\u5206\u652f\uff0c\u4ece\u6700\u540e\u4e00\u884c\u5f00\u59cb\uff0c\u4e00\u65e6\u53d1\u751f\u9519\u8bef\u6216\u8005T\uff0ct\u547d\u4ee4\uff0c\u5c06\u5bfc\u81f4\u5206\u652f\u5230\u5e26\u6709\u6807\u53f7\u7684\u547d\u4ee4\u5904\uff0c\u6216\u8005\u5230\u811a\u672c\u7684\u672b\u5c3e;
\r\n w file \u5199\u5e76\u8ffd\u52a0\u6a21\u677f\u5757\u5230file\u672b\u5c3e;
\r\n W file \u5199\u5e76\u8ffd\u52a0\u6a21\u677f\u5757\u7684\u7b2c\u4e00\u884c\u5230file\u672b\u5c3e;
\r\n ! \u8868\u793a\u540e\u9762\u7684\u547d\u4ee4\u5bf9\u6240\u6709\u6ca1\u6709\u88ab\u9009\u5b9a\u7684\u884c\u53d1\u751f\u4f5c\u7528;
\r\n = \u6253\u5370\u5f53\u524d\u884c\u53f7;
\r\n # \u628a\u6ce8\u91ca\u6269\u5c55\u5230\u4e0b\u4e00\u4e2a\u6362\u884c\u7b26\u4ee5\u524d;\r\n<\/pre>\n\r\n g \u8868\u793a\u884c\u5185\u5168\u9762\u66ff\u6362;
\r\n p \u8868\u793a\u6253\u5370\u884c;
\r\n w \u8868\u793a\u628a\u884c\u5199\u5165\u4e00\u4e2a\u6587\u4ef6;
\r\n x \u8868\u793a\u4e92\u6362\u6a21\u677f\u5757\u4e2d\u7684\u6587\u672c\u548c\u7f13\u51b2\u533a\u4e2d\u7684\u6587\u672c;
\r\n y \u8868\u793a\u628a\u4e00\u4e2a\u5b57\u7b26\u7ffb\u8bd1\u4e3a\u53e6\u5916\u7684\u5b57\u7b26\uff08\u4f46\u662f\u4e0d\u7528\u4e8e\u6b63\u5219\u8868\u8fbe\u5f0f\uff09;
\r\n \\1 \u5b50\u4e32\u5339\u914d\u6807\u8bb0;
\r\n & \u5df2\u5339\u914d\u5b57\u7b26\u4e32\u6807\u8bb0;\r\n<\/pre>\n\r\n ^ \u5339\u914d\u884c\u5f00\u59cb\uff0c\u5982\uff1a\/^sed\/\u5339\u914d\u6240\u6709\u4ee5sed\u5f00\u5934\u7684\u884c;
\r\n $ \u5339\u914d\u884c\u7ed3\u675f\uff0c\u5982\uff1a\/sed$\/\u5339\u914d\u6240\u6709\u4ee5sed\u7ed3\u5c3e\u7684\u884c;
\r\n . \u5339\u914d\u4e00\u4e2a\u975e\u6362\u884c\u7b26\u7684\u4efb\u610f\u5b57\u7b26\uff0c\u5982\uff1a\/s.d\/\u5339\u914ds\u540e\u63a5\u4e00\u4e2a\u4efb\u610f\u5b57\u7b26\uff0c\u6700\u540e\u662fd;
\r\n * \u5339\u914d0\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\uff0c\u5982\uff1a\/*sed\/\u5339\u914d\u6240\u6709\u6a21\u677f\u662f\u4e00\u4e2a\u6216\u591a\u4e2a\u7a7a\u683c\u540e\u7d27\u8ddfsed\u7684\u884c;
\r\n [] \u5339\u914d\u4e00\u4e2a\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5b57\u7b26\uff0c\u5982\/[ss]ed\/\u5339\u914dsed\u548cSed;
\r\n [^] \u5339\u914d\u4e00\u4e2a\u4e0d\u5728\u6307\u5b9a\u8303\u56f4\u5185\u7684\u5b57\u7b26\uff0c\u5982\uff1a\/[^A-RT-Z]ed\/\u5339\u914d\u4e0d\u5305\u542bA-R\u548cT-Z\u7684\u4e00\u4e2a\u5b57\u6bcd\u5f00\u5934\uff0c\u7d27\u8ddfed\u7684\u884c;
\r\n \\(..\\) \u5339\u914d\u5b50\u4e32\uff0c\u4fdd\u5b58\u5339\u914d\u7684\u5b57\u7b26\uff0c\u5982s\/\\(love\\)able\/\\1rs\uff0cloveable\u88ab\u66ff\u6362\u6210lovers;
\r\n & \u4fdd\u5b58\u641c\u7d22\u5b57\u7b26\u7528\u6765\u66ff\u6362\u5176\u4ed6\u5b57\u7b26\uff0c\u5982s\/love\/**&**\/\uff0clove\u8fd9\u6210**love**;
\r\n \\< \u5339\u914d\u5355\u8bcd\u7684\u5f00\u59cb\uff0c\u5982:\/\\
\r\n x\\{m\\} \u91cd\u590d\u5b57\u7b26x\uff0cm\u6b21\uff0c\u5982\uff1a\/0\\{5\\}\/\u5339\u914d\u5305\u542b5\u4e2a0\u7684\u884c;
\r\n x\\{m,\\} \u91cd\u590d\u5b57\u7b26x\uff0c\u81f3\u5c11m\u6b21\uff0c\u5982\uff1a\/0\\{5,\\}\/\u5339\u914d\u81f3\u5c11\u67095\u4e2a0\u7684\u884c;
\r\n x\\{m,n\\} \u91cd\u590d\u5b57\u7b26x\uff0c\u81f3\u5c11m\u6b21\uff0c\u4e0d\u591a\u4e8en\u6b21\uff0c\u5982\uff1a\/0\\{5,10\\}\/\u5339\u914d5~10\u4e2a0\u7684\u884c;\r\n<\/pre>\n sed 's\/book\/books\/' file<\/pre>\n
sed -n 's\/test\/TEST\/p' file<\/pre>\n
sed -i 's\/book\/books\/g' file<\/pre>\n
sed 's\/book\/books\/g' file<\/pre>\n
echo sksksksksksk | sed 's\/sk\/SK\/2g' \r\n skSKSKSKSKSK\r\n echo sksksksksksk | sed 's\/sk\/SK\/3g'\r\n skskSKSKSKSK \r\n echo sksksksksksk | sed 's\/sk\/SK\/4g'\r\n skskskSKSKSK \r\n<\/pre>\n
sed 's:test:TEXT:g' \r\n sed 's|test|TEXT|g' <\/pre>\n
sed 's\/\\\/bin\/\\\/usr\\\/local\\\/bin\/g'<\/pre>\n
sed '\/^$\/d' file<\/pre>\n
sed '2d' file<\/pre>\n
sed '2,$d' file<\/pre>\n
sed '$d' file<\/pre>\n
sed '\/^test\/'d file<\/pre>\n
echo this is a test line | sed 's\/\\w\\+\/[&]\/g'\r\n [this] [is] [a] [test] [line] <\/pre>\n
sed 's\/^192.168.0.1\/&localhost\/' file 192.168.0.1localhost<\/pre>\n
echo this is digit 7 in a number | sed 's\/digit \\([0-9]\\)\/\\1\/' \r\n this is 7 in a number<\/pre>\n
echo aaa BBB | sed 's\/\\([a-z]\\+\\) \\([A-Z]\\+\\)\/\\2 \\1\/' \r\n BBB aaa<\/pre>\n
sed -n 's\/\\(love\\)able\/\\1rs\/p' file<\/pre>\n
sed '\u8868\u8fbe\u5f0f' | sed '\u8868\u8fbe\u5f0f' \u7b49\u4ef7\u4e8e\uff1a \r\n sed '\u8868\u8fbe\u5f0f; \u8868\u8fbe\u5f0f'<\/pre>\n
\r\n test=hello \r\n echo hello WORLD | sed \"s\/$test\/HELLO\" \r\n HELLO WORLD\r\n<\/pre>\n
sed -n '\/test\/,\/check\/p' file<\/pre>\n
sed -n '5,\/^test\/p' file<\/pre>\n
sed '\/test\/,\/west\/s\/$\/aaa bbb\/' file<\/pre>\n
sed -e '1,5d' -e 's\/test\/check\/' file<\/pre>\n
sed --expression='s\/test\/check\/' --expression='\/love\/d' file<\/pre>\n
sed '\/test\/r file' filename<\/pre>\n
\n \u00a0
\n\u5728example\u4e2d\u6240\u6709\u5305\u542btest\u7684\u884c\u90fd\u88ab\u5199\u5165file\u91cc\uff1a <\/p>\n sed -n '\/test\/w file' example<\/pre>\n
sed '\/^test\/a\\this is a test line' file<\/pre>\n
sed -i '2a\\this is a test line' test.conf <\/pre>\n
sed '\/^test\/i\\this is a test line' file<\/pre>\n
sed -i '5i\\this is a test line' test.conf<\/pre>\n
sed '\/test\/{ n; s\/aa\/bb\/; }' file <\/pre>\n
sed '1,10y\/abcde\/ABCDE\/' file<\/pre>\n
sed -e '\/test\/h' -e '$G' file <\/pre>\n
sed -e '\/test\/h' -e '\/check\/x' file <\/pre>\n
sed [options] -f scriptfile file(s)<\/pre>\n
sed -n 'p;n' test.txt #\u5947\u6570\u884c sed -n 'n;p' test.txt #\u5076\u6570\u884c <\/pre>\n
sed -n '1~2p' test.txt #\u5947\u6570\u884c sed -n '2~2p' test.txt #\u5076\u6570\u884c <\/pre>\n
\r\n grep -A 1 SCC URFILE \r\n sed -n '\/SCC\/{n;p}' URFILE \r\n awk '\/SCC\/{getline; print}' URFILE\r\n<\/pre>\n
\n