当前位置:网站首页>Shell nl命令详解(显示行号、读取文件)
Shell nl命令详解(显示行号、读取文件)
2022-08-01 17:01:00 【墨痕诉清风】
nl命令在linux系统中用来计算文件中行号。nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等等的功能。
参数说明

使用实例
log2012.log 文件内容如下:
2012-01
2012-02
======实例1:用 nl 列出 log2012.log 的内容
命令
nl log2012.log输出:
[[email protected] test]# nl log2012.log
1 2012-01
2 2012-02
3 ======
[[email protected] test]#说明:
文件中的空白行,nl 不会加上行号
实例2:用 nl 列出 log2012.log 的内容,空本行也加上行号
命令:
nl -b a log2012.log输出:
[[email protected] test]# nl -b a log2012.log
1 2012-01
2 2012-02
3
4
5 ======
[[email protected] test]#实例3:让行号前面自动补上0,统一输出格式
命令:
nl -b a -n rz log2014.log
nl -b a -n rz -w 3 log2014.log 输出:
[[email protected] test]# nl -b a -n rz log2014.log
000001 2014-01
000002 2014-02
000003 2014-03
000004 2014-04
000005 2014-05
000006 2014-06
000007 2014-07
000008 2014-08
000009 2014-09
000010 2014-10
000011 2014-11
000012 2014-12
000013 =======
[[email protected] test]# nl -b a -n rz -w 3 log2014.log
001 2014-01
002 2014-02
003 2014-03
004 2014-04
005 2014-05
006 2014-06
007 2014-07
008 2014-08
009 2014-09
010 2014-10
011 2014-11
012 2014-12
013 =======说明:
nl -b a -n rz 命令行号默认为六位,要调整位数可以加上参数 -w 3 调整为3位。
实例4:从0开始计数
命令:
nl -v 0 log2012.log输出:
0 2012-01
1 2012-02
2 ======实例5:使用定制的编号分隔符
nl -s :: rumenz.txt
1::入门小站
2::rumenz
3::ping
4::入门边栏推荐
- 深圳市商务局2022年度中央资金(跨境电子商务企业市场开拓扶持事项)申报指南
- GridControl helper class for DevExpress
- 主流小程序框架性能分析
- 2022年深圳市促进大健康产业集群高质量发展的若干措施
- 深入分析类加载器
- Detailed explanation of the working principle of crystal oscillator
- C # Excel helper classes
- 网站备案后没有找到站点 您没有将此域名或IP绑定到对应站点! 配置文件未生效!
- 面对营销难,有米云指出一条破局之路
- 2022.08月--pushmall推贴共享电商更新与开发计划
猜你喜欢

Xingtu has been short of disruptive products?Will this M38T from the Qingdao factory be a breakthrough?

OneFlow源码解析:Op、Kernel与解释器

机器学习快速入门

下载 | 谷歌科学家Kevin P. Murphy发布新书《概率机器学习:高级主题》

2022 Strong Net Cup CTF---Strong Net Pioneer ASR wp

22年镜头“卷”史,智能手机之战卷进死胡同

泰国 好产品推荐!2022年最好的胶原蛋白评测有哪些? 喝出健康和美丽适合需要改善肌肤

好家伙,公司服务器直接热崩掉了!

70后夫妻给苹果华为做“雨衣”,三年进账7.91亿

今晚直播!
随机推荐
Detailed explanation of the working principle of crystal oscillator
Using Canvas to achieve web page mouse signature effect
首席工程师究竟是怎样的存在?
M1芯片电脑安装cerebro
How can become a good architect necessary skills: painting for all the people praise the system architecture diagram?What is the secret?Quick to open this article and have a look!.
在码云拉取代码后,调整了seata版本1.5.2。出现如下异常。是因为数据库表缺少字段导致的吗?
PAT 甲级 A1003 Emergency
素域和扩域
银行案例|Zabbix跨版本升级指南,4.2-6.0不香吗?
Xingtu has been short of disruptive products?Will this M38T from the Qingdao factory be a breakthrough?
SQL函数 TO_CHAR(一)
研发团队数字化转型实践
ROS2支持技术:DDS简述
完全背包问题求组合数和排列数
Bugku-Misc-贝斯手
70后夫妻给苹果华为做“雨衣”,三年进账7.91亿
今晚直播!
[Dark Horse Morning Post] Hu Jun's endorsement of Wukong's financial management is suspected of fraud, which is suspected to involve 39 billion yuan; Fuling mustard responded that mustard ate toenails
软件测试谈薪技巧:同为测试人员,为什么有人5K,有人 20K?
OneFlow源码解析:Op、Kernel与解释器