您的位置:首页 > 运维架构 > Linux

nl 添加行号打印

2012-10-10 09:06 281 查看
[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]$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  centos