添加行号打印文件
##语法
[root@study ~]# nl [-bnw] 文件
##参数
-b: 指定行号指定的方式,主要有两种:
-b a: 表示不论是否为空行,也同样列出行号(类似 cat -n)
-b t: 如果有空行,空的那一行不要列出行号(默认值)
-n: 列出行号表示的方法,主要有三种:
-n ln: 行号在屏幕的最左方显示
-n rn: 行号在自己字段的最右边显示,且不加0;
-n rz: 行号在自己字段的最右边显示,且加0;
-w: 行号字段的占用的字符数
##范例
范例一:用nl列出/etc/issue/的内容
[root@study ~]# nl /etc/issue
1 \S
2 Kernel \r on an \m
# 注意看,这个文件其实有三行,第三行为空白(没有任何字符)
# 因为他是空白行,所以nl不会加上行号喔?如果确定加上行号,可以这样做:
[root@study ~]# nl -b a -n rz /etc/issue
000001 \S
000002 Kernel \r on an \m
000003
# 自动在自己的字段补0了~默认字段是6位数,如果想要改成3位数
[root@study ~]# nl -b a -n rz -w 3 /etc/issue
001 \s
002 Kernel \r on an \m
003