{"rsdb":{"rid":"345894","subhead":"","postdate":"0","aid":"246415","fid":"87","uid":"1","topic":"1","content":"
\n

\u6587\u7ae0\u8f6c\u8f7d\u81ea:http:\/\/www.python<\/a>heidong.com\/blog\/article\/2566\/<\/a><\/p> \n

\u3000\u3000\u8f6c\u81ea\uff1ahttp:\/\/blog.csdn.net\/year_9\/article\/details\/20318407<\/p> \n

\u3000\u3000<\/p> \n

\u3000\u3000sed\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u6587\u4ef6\u5904\u7406\u5de5\u5177\uff0c\u4e3b\u8981\u662f\u4ee5\u884c\u4e3a\u5355\u4f4d\u8fdb\u884c\u5904\u7406\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.(\u603b\uff1ased\u5904\u7406\u5bf9\u8c61\u662f\u6587\u4ef6\uff0c\u600e\u4e48\u5904\u7406\uff1f\u662f\u4ee5\u9010\u884c\u5904\u7406\uff0c\u4f55\u79cd\u5904\u7406\uff1f\u66ff\u6362\uff0c\u5220\u9664\u3002\u3002)
sed\u547d\u4ee4\u884c\u683c\u5f0f\u4e3a\uff1a<\/p> \n

         sed [-nefri] \u2018command\u2019 \u8f93\u5165\u6587\u672c       
<\/span><\/p> \n

\u5e38\u7528\u9009\u9879\uff1a
<\/span><\/p> \n

        -i\u2236\u76f4\u63a5\u4fee\u6539\u8bfb\u53d6\u7684\u6863\u6848\u5185\u5bb9\uff0c\u800c\u4e0d\u662f\u7531\u8424\u5e55\u8f93\u51fa\u3002<\/span><\/p> \n

        -n\u2236\u4f7f\u7528\u5b89\u9759(silent)\u6a21\u5f0f\u3002\u5728\u4e00\u822c sed \u7684\u7528\u6cd5\u4e2d\uff0c\u6240\u6709\u6765\u81ea STDIN\u7684\u8d44\u6599\u4e00\u822c\u90fd\u4f1a\u88ab\u5217\u51fa\u5230\u8424\u5e55\u4e0a\u3002\u4f46\u5982\u679c\u52a0\u4e0a -n \u53c2\u6570\u540e\uff0c\u5219\u53ea\u6709\u7ecf\u8fc7sed \u7279\u6b8a\u5904\u7406\u7684\u90a3\u4e00\u884c(\u6216\u8005\u52a8\u4f5c)\u624d\u4f1a\u88ab\u5217\u51fa\u6765\u3002
<\/span><\/span><\/p> \n

\u5e38\u7528\u547d\u4ee4\uff1a
        a   \u2236\u65b0\u589e\uff0c a \u7684\u540e\u9762\u53ef\u4ee5\u63a5\u5b57\u4e32\uff0c\u800c\u8fd9\u4e9b\u5b57\u4e32\u4f1a\u5728\u65b0\u7684\u4e00\u884c\u51fa\u73b0(\u76ee\u524d\u7684\u4e0b\u4e00\u884c)\uff5e \u5982\uff1ased '1a End' \u5728\u6700\u540e\u4e00\u884c\u540e\u518d\u63d2\u5165\u4e00\u884cEnd\uff08\u9762\u8bd5\u9898\uff09
        c   \u2236\u53d6\u4ee3\uff0c c \u7684\u540e\u9762\u53ef\u4ee5\u63a5\u5b57\u4e32\uff0c\u8fd9\u4e9b\u5b57\u4e32\u53ef\u4ee5\u53d6\u4ee3 n1,n2 \u4e4b\u95f4\u7684\u884c\uff01
        d   \u2236\u5220\u9664\uff0c\u56e0\u4e3a\u662f\u5220\u9664\u554a\uff0c\u6240\u4ee5 d \u540e\u9762\u901a\u5e38\u4e0d\u63a5\u4efb\u4f55\u549a\u549a\uff1b
         i   \u2236\u63d2\u5165\uff0c i \u7684\u540e\u9762\u53ef\u4ee5\u63a5\u5b57\u4e32\uff0c\u800c\u8fd9\u4e9b\u5b57\u4e32\u4f1a\u5728\u65b0\u7684\u4e00\u884c\u51fa\u73b0(\u76ee\u524d\u7684\u4e0a\u4e00\u884c)\uff1b
         s  \u2236\u53d6\u4ee3\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fdb\u884c\u53d6\u4ee3\u7684\u5de5\u4f5c\u54e9\uff01\u901a\u5e38\u8fd9\u4e2a s \u7684\u52a8\u4f5c\u53ef\u4ee5\u642d\u914d\u6b63\u89c4\u8868\u793a\u6cd5\uff01\u4f8b\u5982 1,20s\/old\/new\/g \u5c31\u662f\u5566\uff01<\/span><\/span><\/p> \n

         p  \u2236\u5217\u5370\uff0c\u4ea6\u5373\u5c06\u67d0\u4e2a\u9009\u62e9\u7684\u8d44\u6599\u5370\u51fa\u3002\u901a\u5e38 p \u4f1a\u4e0e\u53c2\u6570 sed -n \u4e00\u8d77\u8fd0\u4f5c\uff5e
<\/span><\/span><\/p> \n

\u4e3e\u4f8b\uff1a\uff08\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u6587\u4ef6\u540d\u4e3aab\uff09
     \u5220\u9664\u67d0\u884c
     [root@localhost ruby]# sed '1d' ab              #\u5220\u9664\u7b2c\u4e00\u884c 
     [root@localhost ruby] # sed '$d' ab              #\u5220\u9664\u6700\u540e\u4e00\u884c
     [root@localhost ruby] # sed '1,2d' ab           #\u5220\u9664\u7b2c\u4e00\u884c\u5230\u7b2c\u4e8c\u884c
     [root@localhost ruby] # sed '2,$d' ab           #\u5220\u9664\u7b2c\u4e8c\u884c\u5230\u6700\u540e\u4e00\u884c<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p> \n

\u663e\u793a\u67d0\u884c
.    [root@localhost ruby]# sed -n '1p' ab           #\u663e\u793a\u7b2c\u4e00\u884c 
     [root@localhost ruby] # sed -n '$p' ab           #\u663e\u793a\u6700\u540e\u4e00\u884c
     [root@localhost ruby] # sed -n '1,2p' ab        #\u663e\u793a\u7b2c\u4e00\u884c\u5230\u7b2c\u4e8c\u884c
     [root@localhost ruby] # sed -n '2,$p' ab        #\u663e\u793a\u7b2c\u4e8c\u884c\u5230\u6700\u540e\u4e00\u884c<\/span><\/span><\/span><\/span><\/span><\/p> \n


<\/p> \n

\u4f7f\u7528\u6a21\u5f0f\u8fdb\u884c\u67e5\u8be2
     [root@localhost ruby] # sed -n '\/ruby\/p' ab    #\u67e5\u8be2\u5305\u62ec\u5173\u952e\u5b57ruby\u6240\u5728\u6240\u6709\u884c
     [root@localhost ruby] # sed -n '\/\\$\/p' ab        #\u67e5\u8be2\u5305\u62ec\u5173\u952e\u5b57$\u6240\u5728\u6240\u6709\u884c\uff0c\u4f7f\u7528\u53cd\u659c\u7ebf\\\u5c4f\u853d\u7279\u6b8a\u542b\u4e49<\/span><\/span><\/p> \n

\u3000\u3000\u589e\u52a0\u4e00\u884c\u6216\u591a\u884c\u5b57\u7b26\u4e32
     [root@localhost ruby]# cat ab
     Hello!
     ruby is me,welcome to my blog.
     end
     [root@localhost ruby] # sed '1a drink tea' ab  #\u7b2c\u4e00\u884c\u540e\u589e\u52a0\u5b57\u7b26\u4e32"drink tea"
     Hello!
     drink tea
     ruby is me,welcome to my blog. 
     end
     [root@localhost ruby] # sed '1,3a drink tea' ab #\u7b2c\u4e00\u884c\u5230\u7b2c\u4e09\u884c\u540e\u589e\u52a0\u5b57\u7b26\u4e32"drink tea"
     H","orderid":"0","title":"\u5982\u4f55\u66ff\u6362\u67d0\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u7684\u7279\u5b9a\u5b57\u7b26\uff1f---linux sed\u547d\u4ee4\uff08\u6587\u672c\u7f16\u8f91\u547d\u4ee4\uff09 \uff08\u8f6c\u8f7d\uff09(\u4e00)","smalltitle":"","mid":"0","fname":"Ruby","special_id":"0","bak_id":"0","info":"0","hits":"426","pages":"2","comments":"0","posttime":"2019-09-03 02:40:36","list":"1567449636","username":"admin","author":"","copyfrom":"","copyfromurl":"","titlecolor":"","fonttype":"0","titleicon":"0","picurl":"https:\/\/www.cppentry.com\/upload_files\/","ispic":"0","yz":"1","yzer":"","yztime":"0","levels":"0","levelstime":"0","keywords":"
\u5982\u4f55<\/A> \u66ff\u6362<\/A> \u6587\u4ef6<\/A> \u6709\u7684<\/A> \u7279\u5b9a<\/A> \u5b57\u7b26<\/A> ---linux<\/A> sed<\/A> \u547d\u4ee4<\/A> \u6587\u672c<\/A> \u7f16\u8f91<\/A> \u8f6c\u8f7d<\/A>","jumpurl":"","iframeurl":"","style":"","template":"a:3:{s:4:\"head\";s:0:\"\";s:4:\"foot\";s:0:\"\";s:8:\"bencandy\";s:0:\"\";}","target":"0","ip":"120.229.33.54","lastfid":"0","money":"0","buyuser":"","passwd":"","allowdown":"","allowview":"","editer":"","edittime":"0","begintime":"0","endtime":"0","description":"\u5982\u4f55\u66ff\u6362\u67d0\u6587\u4ef6\u4e2d\u7684\u6240\u6709\u7684\u7279\u5b9a\u5b57\u7b26\uff1f---linux sed\u547d\u4ee4\uff08\u6587\u672c\u7f16\u8f91\u547d\u4ee4\uff09 \uff08\u8f6c\u8f7d\uff09","lastview":"1714192505","digg_num":"0","digg_time":"0","forbidcomment":"0","ifvote":"0","heart":"","htmlname":"","city_id":"0"},"page":"1"}