nl命令用法举例

nl命令
1.命令格式:nl [选项]... [文件]...
2.命令参数:
-b:指定行号指定的方式,主要有两种:
    -b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
    -b t :如果有空行,空的那一行不要列出行号(默认值);

-n:列出行号表示的方法,主要有三种:
   -n ln :行号在萤幕的最左方显示;
   -n rn :行号在自己栏位的最右方显示,且不加 0 ;
   -n rz :行号在自己栏位的最右方显示,且加 0 ;
[hduser0401@dev-l002782 ~]$ nl -n ln test0929.txt
1       1,test01
2       2,test02
       
3       3,test03
4       4,test04
5       5,test05
[hduser0401@dev-l002782 ~]$ nl -n rn test0929.txt
     1  1,test01
     2  2,test02
       
     3  3,test03
     4  4,test04
     5  5,test05
[hduser0401@dev-l002782 ~]$ nl -n rz test0929.txt
000001  1,test01
000002  2,test02
       
000003  3,test03
000004  4,test04
   
-w:行号栏位的占用的位数。
-p 在逻辑定界符处不重新开始计算。 
[hduser0401@dev-l002782 ~]$ nl -p test0929.txt
     1  1,test01
     2  2,test02
       
     3  3,test03
     4  4,test04
     5  5,test05
[hduser0401@dev-l002782 ~]$ nl -bt test0929.txt
     1  1,test01
     2  2,test02
       
     3  3,test03
     4  4,test04
     5  5,test05
     
3.命令功能:
在linux系统中用来计算文件中行号。nl可以将输出的文件内容自动的加上行号!
其默认的结果与cat -n有点不太一样,nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐0等的功能。  

4.使用实例:
4.1用nl列出文件的内容: nl 文件名
[hduser0401@dev-l002782 ~]$ nl test0929.txt
     1  1,test01
     2  2,test02
       
     3  3,test03
     4  4,test04
     5  5,test05
[hduser0401@dev-l002782 ~]$ cat -n test0929.txt
     1  1,test01
     2  2,test02
     3
     4  3,test03
     5  4,test04
     
文件中的空白行,nl不会加上行号,cat -n加上行号

4.2用nl列出文件的内容,空白行也加行号: nl -b a 文件名
[hduser0401@dev-l002782 ~]$ nl -b a test0929.txt
     1  1,test01
     2  2,test02
     3
     4  3,test03
     5  4,test04
     6  5,test05
     
[hduser0401@dev-l002782 ~]$ nl -ba test0929.txt
     1  1,test01
     2  2,test02
     3
     4  3,test03
     5  4,test04

4.3让行号前面自动补上0,统一输出格式
[hduser0401@dev-l002782 ~]$ nl -b a -n rz test0929.txt
000001  1,test01
000002  2,test02
000003
000004  3,test03
000005  4,test04
000006  5,test05
=>
[hduser0401@dev-l002782 ~]$ nl -ba -nrz test0929.txt
000001  1,test01
000002  2,test02
000003
000004  3,test03
000005  4,test04

[hduser0401@dev-l002782 ~]$ nl -b a -n rz -w 3 test0929.txt
001     1,test01
002     2,test02
003
004     3,test03
005     4,test04
006     5,test05
=>
[hduser0401@dev-l002782 ~]$ nl -ba -nrz -w3 test0929.txt
001     1,test01
002     2,test02
003
004     3,test03
005     4,test04
006     5,test05
说明:nl -b a -n rz 命令行号默认为六位,要调整位数,可以加上参数-w n(位数)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值