linux 命令——11 nl (轉)

來源:互聯網
上載者:User

標籤:

  nl命令在linux系統中用來計算檔案中行號。nl 可以將輸出的檔案內容自動的加上行號!其預設的結果與 cat -n 有點不太一樣, nl 可以將行號做比較多的顯示設計,包括位元與是否自動補齊 0 等等的功能。  

1.命令格式:

nl [選項]... [檔案]...

2.命令參數:

-b  :指定行號指定的方式,主要有兩種:

  -b a :表示不論是否為空白行,也同樣列出行號(類似 cat -n);

  -b t :如果有空行,空的那一行不要列出行號(預設值);

-n  :列出行號表示的方法,主要有三種:

  -n ln :行號在螢幕的最左方顯示;

  -n rn :行號在自己欄位的最右方顯示,且不加 0 ;

  -n rz :行號在自己欄位的最右方顯示,且加 0 ;

-w  :行號欄位的佔用的位元。

-p 在邏輯定界符處不重新開始計算。 

 

3.命令功能:

nl 命 令讀取 File 參數(預設情況下標準輸入),計算輸入中的行號,將計算過的行號寫入標準輸出。 在輸出中,nl 命令根據您在命令列中指定的標誌來計 算左邊的行。 輸入文本必須寫在邏輯頁中。每個邏輯頁有頭、主體和頁尾節(可以有空節)。 除非使用 -p 標誌,nl 命令在每個邏輯頁開始的地方重新 設定行號。 可以單獨為頭、主體和頁尾節設定行計算標誌(例如,頭和頁尾行可以被計算然而文本行不能)。

4.使用執行個體:

執行個體一:用 nl 列出 log2012.log 的內容

命令:

nl log2012.log

輸出:

[[email protected] test]# nl log2012.log 

     1  2012-01

     2  2012-02

       

    

     3  ======[[email protected] test]#

說明:

檔案中的空白行,nl 不會加上行號

 

執行個體二:用 nl 列出 log2012.log 的內容,空本行也加上行號

命令:

nl -b a log2012.log

輸出:

[[email protected] test]# nl -b a log2012.log 

     1  2012-01

     2  2012-02

     3

     4

     5  ======[[email protected] test]#

 

執行個體3:讓行號前面自動補上0,統一輸出格式

命令:

輸出:

[[email protected] test]# nl -b a -n rz log2014.log 

000001  2014-01

000002  2014-02

000003  2014-03

000004  2014-04

000005  2014-05

000006  2014-06

000007  2014-07

000008  2014-08

000009  2014-09

000010  2014-10

000011  2014-11

000012  2014-12

000013  =======

[[email protected] test]# nl -b a -n rz -w 3 log2014.log 

001     2014-01

002     2014-02

003     2014-03

004     2014-04

005     2014-05

006     2014-06

007     2014-07

008     2014-08

009     2014-09

010     2014-10

011     2014-11

012     2014-12

013     =======

說明:

nl -b a -n rz 命令列號預設為六位,要調整位元可以加上參數 -w 3 調整為3位。

linux 命令——11 nl (轉)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.