zhyiwww
          用平實(shí)的筆,記錄編程路上的點(diǎn)點(diǎn)滴滴………
          posts - 536,comments - 394,trackbacks - 0

          注意參數(shù)-n

          (1)顯示某一行或某些行

          顯示1,10行
          $ sed -n '1,10p' postgres.conf

          顯示第10行
          $ sed -n '10p' postgres.conf

          (2)顯示某些匹配行
          $ sed -n '/This/p' postgres.conf

          我的測(cè)試:

          XYZ@XYZ-desktop:~$ sed -n '1,10 p' postgresql.conf??
          # -----------------------------
          # PostgreSQL configuration file
          # -----------------------------
          #
          # This file consists of lines of the form:
          #
          #?? name = value
          #
          # (The "=" is optional.)? Whitespace may be used.? Comments are introduced with
          # "#" anywhere on a line.? The complete list of parameter names and allowed
          XYZ@XYZ-desktop:~$ sed -n '10p' postgresql.conf?
          # "#" anywhere on a line.? The complete list of parameter names and allowed
          XYZ@XYZ-desktop:~$ sed -n '/This/p' postgresql.conf?
          # This file consists of lines of the form:
          # This file is read on server startup and when the server receives a SIGHUP
          # This is used when logging to stderr:
          XYZ@XYZ-desktop:~$?


          下面的部分來自網(wǎng)上,對(duì)于上面的理解會(huì)更充分:
          Relations between d, p, and !
          Sed Range Command Results
          --------------------------------------------------------
          sed -n 1,10 p Print first 10 lines
          sed -n 11,$ !p Print first 10 lines
          sed 1,10 !d Print first 10 lines
          sed 11,$ d Print first 10 lines
          --------------------------------------------------------
          sed -n 1,10 !p Print last 10 lines
          sed -n 11,$ p Print last 10 lines
          sed 1,10 d Print last 10 lines
          sed 11,$ !d Print last 10 lines
          --------------------------------------------------------
          sed -n 1,10 d Nothing printed
          sed -n 1,10 !d Nothing printed
          sed -n 11,$ d Nothing printed
          sed -n 11,$ !d Nothing printed
          --------------------------------------------------------
          sed 1,10 p Print first 10 lines twice,
          Then next 10 lines once
          sed 11,$ !p Print first 10 lines twice,
          Then last 10 lines once
          --------------------------------------------------------
          sed 1,10 !p Print first 10 lines once,
          Then last 10 lines twice
          sed 11,$ p Print first 10 lines once,
          then last 10 lines twice

          This table shows that the following commands are identical:

          sed -n '1,10 p'
          sed -n '11,$ !p'
          sed '1,10 !d'
          sed '11,$ d'





          |----------------------------------------------------------------------------------------|
                                     版權(quán)聲明  版權(quán)所有 @zhyiwww
                      引用請(qǐng)注明來源 http://www.aygfsteel.com/zhyiwww   
          |----------------------------------------------------------------------------------------|
          posted on 2009-07-22 11:19 zhyiwww 閱讀(12677) 評(píng)論(0)  編輯  收藏 所屬分類: linux
          主站蜘蛛池模板: 铁岭县| 高碑店市| 固原市| 来凤县| 宁明县| 湟中县| 黄梅县| 雅江县| 锦屏县| 游戏| 广宁县| 青川县| 尉犁县| 吐鲁番市| 峨边| 墨竹工卡县| 台安县| 汝城县| 海口市| 台山市| 靖西县| 明溪县| 新建县| 江源县| 娱乐| 宝兴县| 平阳县| 米林县| 海林市| 米脂县| 新田县| 冀州市| 拉孜县| 巴彦县| 西峡县| 图木舒克市| 冷水江市| 彭阳县| 泗洪县| 齐河县| 洪雅县|