zhyiwww
          用平實的筆,記錄編程路上的點點滴滴………
          posts - 536,comments - 394,trackbacks - 0

          注意參數-n

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

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

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

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

          我的測試:

          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:~$?


          下面的部分來自網上,對于上面的理解會更充分:
          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'





          |----------------------------------------------------------------------------------------|
                                     版權聲明  版權所有 @zhyiwww
                      引用請注明來源 http://www.aygfsteel.com/zhyiwww   
          |----------------------------------------------------------------------------------------|
          posted on 2009-07-22 11:19 zhyiwww 閱讀(12679) 評論(0)  編輯  收藏 所屬分類: linux
          主站蜘蛛池模板: 江川县| 安岳县| 清新县| 巴马| 子长县| 丹凤县| 南岸区| 工布江达县| 双峰县| 克拉玛依市| 桦川县| 宁乡县| 富川| 台南县| 桃园市| 东乌珠穆沁旗| 乐东| 香港| 邢台市| 福海县| 壤塘县| 神农架林区| 绥阳县| 淳化县| 兖州市| 芜湖市| 扎囊县| 蒙城县| 城固县| 安吉县| 平山县| 武宁县| 仲巴县| 宣武区| 文登市| 大兴区| 文安县| 沭阳县| 漳浦县| 安阳县| 新田县|