[zhang@test temp]$ nl section.txt
1 line with pattern1
2 line with pattern2
3 line with pattern3
4 line end with pattern4
5 line with pattern5
参数:
-b:指定行号指定的方式,主要有以下两种:
-b a :表示不论是否为空行,也同样列出行号(类似cat -n)
-b t:如果有空行,空的那一行不要列出行号(默认值)
-n:列出行号表示的方法,主要有三种:
-n ln:行号在屏幕的最左方显示;
-n rn:行号在自己字段的最右方显示,且不加0;
-n rz:行号在自己字段的最右方显示,且加0;
-w:行号字段占用的位数。
举例说明:
#用nl列举出issue的内容
[zhang@test temp]$ nl /etc/issue
1 CentOS release 5.5 (Final)
2 Kernel \r on an \m
[zhang@test temp]$ nl -b a /etc/issue
1 CentOS release 5.5 (Final)
2 Kernel \r on an \m
3
[zhang@test temp]$ nl -b a -n rz /etc/issue
000001 CentOS release 5.5 (Final)
000002 Kernel \r on an \m
000003
[zhang@test temp]$ nl -b a -n rz -w 3 /etc/issue
001 CentOS release 5.5 (Final)
002 Kernel \r on an \m
003
[zhang@test temp]$
本文详细介绍了如何使用nl命令来查看文件中每行内容,并通过设置不同的参数来调整行号的显示方式,包括行号的位置、是否显示空行以及行号的格式。
7851

被折叠的 条评论
为什么被折叠?



