nl命令常用参数:
nl命令用来查看一个文本文件,并自动加上行号,默认空行不加行号。
-b a 不论是否是空行,都打印行号
-b t 空行不打印行号,默认参数
-b n 不打印任何行号
示例文本:
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
eeeeeeee
Example:
➜ ~ git:(develop) ✗ nl aa.txt
1 aaaaaaaa
2 bbbbbbbb
3 cccccccc
4 dddddddd
5 eeeeeeee
➜ ~ git:(develop) ✗ nl -b a aa.txt
1 aaaaaaaa
2 bbbbbbbb
3
4 cccccccc
5 dddddddd
6
7 eeeeeeee
➜ ~ git:(develop) ✗ nl -b n aa.txt
aaaaaaaa
bbbbbbbb
cccccccc
dddddddd
eeeeeeee
➜ ~ git:(develop) ✗ nl -b t aa.txt
1 aaaaaaaa
2 bbbbbbbb
3 cccccccc
4 dddddddd
5 eeeeeeee
-s 指定行号和文本内容的分隔符,默认是tab字符
➜ ~ git:(develop) ✗ nl -b a aa.txt
1 aaaaaaaa
2 bbbbbbbb
3
4 cccccccc
5 dddddddd
6
7 eeeeeeee
➜ ~ git:(develop) ✗ nl -b a -s "****" aa.txt
1****aaaaaaaa
2****bbbbbbbb
3****
4****cccccccc
5****dddddddd
6****
7****eeeeeeee
-n :列出行号表示的方法,主要有三种:
-n ln :行号在萤幕的最左方显示;
-n rn :行号在自己栏位的最右方显示,且不加 0
-n rz :行号在自己栏位的最右方显示,且加 0
➜ ~ git:(develop) ✗ nl -n ln aa.txt
1 aaaaaaaa
2 bbbbbbbb
3 cccccccc
4 dddddddd
5 eeeeeeee
➜ ~ git:(develop) ✗ nl -n rn aa.txt
1 aaaaaaaa
2 bbbbbbbb
3 cccccccc
4 dddddddd
5 eeeeeeee
➜ ~ git:(develop) ✗ nl -n rz aa.txt
000001 aaaaaaaa
000002 bbbbbbbb
000003 cccccccc
000004 dddddddd
000005 eeeeeeee
-w 指定行的位数
➜ ~ git:(develop) ✗ nl -w 10 aa.txt
1 aaaaaaaa
2 bbbbbbbb
3 cccccccc
4 dddddddd
5 eeeeeeee