Linux命令之nl

nl命令個人感覺應(yīng)用場景不多,所以就簡單看一下。nl命令主要作用是對文件行號的操作。

1.命令語法

nl [operation] file

[root@vm3 test]# nl test1.txt 
     1  12
     2  123
     3  12344
     4  123445
       
     5  1233545
     6  1231
     7  213213
     8  2143324
     9  45423
    10  324214
    11  123213

2.命令選項

-b:指定行號的方式,主要有兩種
?-b a:表示是否為空行,也同樣列出行號(類似于cat -n)

[root@vm3 test]# nl -b a test1.txt 
     1  12
     2  123
     3  12344
     4  123445
     5  
     6  1233545
     7  1231
     8  213213
     9  2143324
    10  45423
    11  324214
    12  123213

?-b t:如果是空行,跳過空的那一行(默認(rèn))

[root@vm3 test]# nl test1.txt 
     1  12
     2  123
     3  12344
     4  123445
       
     5  1233545
     6  1231
     7  213213
     8  2143324
     9  45423
    10  324214
    11  123213

-n:列出行號表示的方法,主要有三種
?-n ln:行號在屏幕最左方顯示

[root@vm3 test]# nl -n ln test1.txt
1       12
2       123
3       12344
4       123445
       
5       1233545
6       1231
7       213213
8       2143324
9       45423
10      324214
11      123213

?-n rn:行號在行號欄最右方顯示,不加0

[root@vm3 test]# nl -n rn test1.txt 
     1  12
     2  123
     3  12344
     4  123445
       
     5  1233545
     6  1231
     7  213213
     8  2143324
     9  45423
    10  324214
    11  123213

?-n rz:行號在行號欄最右方顯示, 且加0

[root@vm3 test]# nl -n rz test1.txt 
000001  12
000002  123
000003  12344
000004  123445
       
000005  1233545
000006  1231
000007  213213
000008  2143324
000009  45423
000010  324214
000011  123213

-w number:行號欄的占用的位數(shù),其中number為位數(shù)

[root@vm3 test]# nl -w 4 test1.txt 
   1    12
   2    123
   3    12344
   4    123445
     
   5    1233545
   6    1231
   7    213213
   8    2143324
   9    45423
  10    324214
  11    123213

-p:在邏輯定界符處不重新開始計算(沒懂啥意思)

[root@vm3 test]# nl -p test1.txt 
    1  12
    2  123
    3  12344
    4  123445
      
    5  1233545
    6  1231
    7  213213
    8  2143324
    9  45423
   10  324214
   11  123213

參考自nl命令

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容