Linux 命令学习:nl [转载]

1.      命令格式:
  nl [选项] [文件] 
2.      命令功能:
nl命令(number of lines)用来计算文件中行号。nl可以讲输出文件的内容自动加上行号。与cat -n有些不同,nl可以做较多的设计。

3.      常用参数:
  • -b  :指定行号指定的方式,主要有两种:

    • -b a :表示不论是否为空行,也同样列出行号(类似 cat -n);

    • -b t :如果有空行,空的那一行不要列出行号(默认值);

  • -n  :列出行号表示的方法,主要有三种:

    • -n ln :行号在萤幕的最左方显示;

    • -n rn :行号在自己栏位的最右方显示,且不加 0 ;

    • -n rz :行号在自己栏位的最右方显示,且加 0 ;

  • -w  :行号栏位的占用的位数。

  • -p 在逻辑定界符处不重新开始计算。
4.      命令实例
  • nl testlog.log:用nl列出textlog文件的内容,空白行不加行号:
  • [root@localhost test]# nl testlog.log 
         1  2012-01
    
         2  2012-02
    [root@localhost test]#
  • nl -ba testlog.log:用nl列出textlog文件的内容,空白行也加上行号:
  • [root@localhost test]# nl -ba testlog.log 
         1  2012-01
         2  
         3  2012-02
    [root@localhost test]#
  • nl -ba -n rz test.log:让行号自动补上0,同意输出格式:
  • [root@localhost test]# nl -ba -n rz testlog.log 
    000001  2012-01
    000002
    000003  2012-02
    [root@localhost test]#
  • nl -b a -n rz -w 3 testlog.log:nl -b a -n rz 命令行号默认为六位,要调整位数可以加上参数 -w 3 调整为3位。
  • [root@localhost test]# nl -ba -nrz -w3 testlog.log 
    001  2012-01
    002
    003  2012-02
    [root@localhost test]#

  

posted on 2012-12-17 10:23  学习,记录,总结  阅读(282)  评论(0编辑  收藏  举报