• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            大龍的博客

            常用鏈接

            統(tǒng)計

            最新評論

            sed 用法及實例

            1.       打?。簆
            [root@TestAs4 chap04]# cat datafile               原文件
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13

            [root@TestAs4 chap04]# sed  -n '/north/p' datafile   取消默認(rèn)輸出 只打印包含模板的行
            northwest       NW      Charles Main            3.0     .98     3       34
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9

            [root@TestAs4 chap04]# sed '/north/p' datafile       打印包含模板的行及打印默認(rèn)輸出
            northwest       NW      Charles Main            3.0     .98     3       34
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13

            2.       刪除:d
               [root@TestAs4 chap04]# sed '3d'  datafile            刪除第三行
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13

            [root@TestAs4 chap04]# sed '3,$d'  datafile          刪除第三行到最后的所有行
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23

            [root@TestAs4 chap04]# sed '/north/d' datafile        刪除所有包含模板north的行
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            central         CT      Ann Stephens            5.7     .94     5       13

            3.       選定行的范圍:逗號
                [root@TestAs4 chap04]# sed -n '/west/,/east/p' datafile     所有在模板west和east所確定的行都被打印 
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17


            [root@TestAs4 chap04]# sed -n '1,5'p datafile           打印第一、五行的內(nèi)容
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17

            [root@TestAs4 chap04]# sed  '/west/,/east/s/$/**?VACA**/' datafile   對于east和west之間的行,末尾用**?VACA**替換
            northwest       NW      Charles Main            3.0     .98     3       34**?VACA**
            western         WE      Sharon Gray             5.3     .97     5       23**?VACA**
            southwest       SW      Lewis Dalsass           2.7     .8      2       18**?VACA**
            southern        SO      Suan Chin               5.1     .95     4       15**?VACA**
            southeast       SE      Patricia Hemenway       4.0     .7      4       17**?VACA**
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13

            [root@TestAs4 chap04]# sed  -n '/west/,/south/p' datafile                 
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            4.多點編輯:e命令
            [root@TestAs4 chap04]# sed -e '1,3d' -e 's/Hemenway/Jones/' datafile    刪除1到3行,用Hemenway替換Jones
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Jones  4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13


            5. 從文件讀入:r 命令
            [root@TestAs4 chap04]# cat newfile 
                    nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
                    | ***SUAN HAS LEFT THE COMPANY*** |
                    |_________________________________|


            [root@TestAs4 chap04]# sed  '/Suan/r newfile'  datafile       把newfile文件內(nèi)容放到Suan行的下面
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
                    nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
                    | ***SUAN HAS LEFT THE COMPANY*** |
                    |_________________________________|
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13

            注:如果不止一個Suan 則newfile的內(nèi)容就將顯示在所有匹配行的下面

            6. 寫入文件:w命令
            [root@TestAs4 chap04]# sed  -n '/north/w  newfile2'  datafile   命令w表示把所有包含north的行寫入到newfile2

            [root@TestAs4 chap04]# cat newfile2
            northwest       NW      Charles Main            3.0     .98     3       34
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9




            7. 追加:a 命令 
            [root@TestAs4 chap04]#  sed '/^north/a ---->THE NORTH SALES DISTRICT HAS MOVED    
            northwest       NW      Charles Main            3.0     .98     3       34
            ---->THE NORTH SALES DISTRICT HAS MOVED
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            ---->THE NORTH SALES DISTRICT HAS MOVED
            north           NO      Margot Weber            4.5     .89     5        9
            ---->THE NORTH SALES DISTRICT HAS MOVED
            central         CT      Ann Stephens            5.7     .94     5       13
            注: 在出現(xiàn)首個單詞是north的后一行追加---->THE NORTH SALES DISTRICT HAS MOVED行

            8. 插入: i 命令
            [root@TestAs4 chap04]# sed '/eastern/i\
            > NEW ENGLAND REGION\
            > -------------------------------------' datafile
            northwest       NW      Charles Main            3.0     .98     3       34
            western         WE      Sharon Gray             5.3     .97     5       23
            southwest       SW      Lewis Dalsass           2.7     .8      2       18
            southern        SO      Suan Chin               5.1     .95     4       15
            southeast       SE      Patricia Hemenway       4.0     .7      4       17
            NEW ENGLAND REGION
            -------------------------------------
            eastern         EA      TB Savage               4.4     .84     5       20
            northeast       NE      AM Main Jr.             5.1     .94     3       13
            north           NO      Margot Weber            4.5     .89     5        9
            central         CT      Ann Stephens            5.7     .94     5       13

            注:如果模板eastern被匹配,i命令把反斜杠后面的文本插入到包含eastern的行的前面


            9. 替換:s 命令

            [root@TestAs4 oracle]# pwd
            /u01/app/oracle
            [root@TestAs4 oracle]# pwd  | sed  's/\/[^\/]*$/old/'      把“/ u01/app/oracle”的 “/oracle”替換為old 
            /u01/appold
            [root@TestAs4 chap04]# sed -n 's/Hemenway/Jones/pg' datafile      所有的Hemenway行被Jones 替換并打印
            southeast       SE      Patricia Jones  4.0     .7      4       17

            posted on 2011-06-11 23:13 大龍 閱讀(236) 評論(0)  編輯 收藏 引用

            亚洲综合日韩久久成人AV| 久久免费视频观看| 波多野结衣久久精品| 久久精品中文字幕一区| 久久久亚洲欧洲日产国码aⅴ| 伊人久久精品无码av一区| 久久人妻少妇嫩草AV无码专区| 久久99国内精品自在现线| 人妻久久久一区二区三区| 久久久久免费精品国产| 一本色综合久久| 久久91综合国产91久久精品 | 亚洲狠狠婷婷综合久久久久| 久久精品国产乱子伦| 色综合久久天天综合| 少妇熟女久久综合网色欲| 久久精品无码一区二区三区| 精品久久久久久久国产潘金莲| 狠狠色综合久久久久尤物| 国产99久久久国产精品小说| 9191精品国产免费久久| 国产精品无码久久久久久| 模特私拍国产精品久久| 久久久久18| 欧美精品一本久久男人的天堂| 久久久久久九九99精品| 性欧美大战久久久久久久 | 久久天天婷婷五月俺也去| 精品精品国产自在久久高清| 久久亚洲国产最新网站| 久久综合精品国产一区二区三区| 国产一区二区精品久久凹凸| 久久香蕉超碰97国产精品| 久久久久亚洲av成人网人人软件| 热综合一本伊人久久精品| 93精91精品国产综合久久香蕉| 久久午夜伦鲁片免费无码| 久久久无码精品亚洲日韩蜜臀浪潮 | 国产成人精品久久亚洲高清不卡| 国产亚洲综合久久系列| 99久久国产精品免费一区二区 |