nl 添加行号打印

本文详细介绍了如何使用nl命令来查看文件中每行内容,并通过设置不同的参数来调整行号的显示方式,包括行号的位置、是否显示空行以及行号的格式。


[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]$

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值