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
网友评论