1. 命令解析
命令用途:
將文件內容輸出到標準輸出,并添加上行號;若沒有指定文件,或指定的文件名為-則讀取標準輸入作為數據源;
命令格式:
nl [OPTION]... [FILE]...
命令參數:
-b, --body-numbering=STYLE use STYLE for numbering body lines
-d, --section-delimiter=CC use CC for separating logical pages
-f, --footer-numbering=STYLE use STYLE for numbering footer lines
-h, --header-numbering=STYLE use STYLE for numbering header lines
-i, --line-increment=NUMBER line number increment at each line
-l, --join-blank-lines=NUMBER group of NUMBER empty lines counted as one
-n, --number-format=FORMAT insert line numbers according to FORMAT
-p, --no-renumber do not reset line numbers at logical pages
-s, --number-separator=STRING add STRING after (possible) line number
-v, --starting-line-number=NUMBER first line number on each logical page
-w, --number-width=NUMBER use NUMBER columns for line numbers
--help display this help and exit
--version output version information and exit
2. 示例
2.1 無參顯示文件內容及行號(空行不顯示行號)
[root@test nlTest]# cat f1
This is
My
File
After blank
is still file content
[root@test nlTest]# nl f1
1 This is
2 My
3 File
4 After blank
5 is still file content
2.2 顯示空行的行號 -b
[root@test nlTest]# nl -b a f1
1 This is
2 My
3 File
4
5 After blank
6 is still file content
2.3 顯示行號且指定格式 -n
[root@test nlTest]# nl -n ln f1
1 This is
2 My
3 File
4 After blank
5 is still file content
[root@test nlTest]# nl -n rn f1
1 This is
2 My
3 File
4 After blank
5 is still file content
[root@test nlTest]# nl -n rz f1
000001 This is
000002 My
000003 File
000004 After blank
000005 is still file content
2.4 指定格式位數 -n -w
[root@test nlTest]# nl -n rz -w 3 f1
001 This is
002 My
003 File
004 After blank
005 is still file content