当前位置:网站首页>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::入门边栏推荐
- Description of common operations and help projects about DevExpress in C#
- 08 Spark cluster construction
- 2022年深圳市促进大健康产业集群高质量发展的若干措施
- LeetCode第 303 场周赛
- 吴恩达机器学习课后习题——kmeans
- 开发工具:第五章:使用idea生成实体类
- 统信软件、龙芯中科等四家企业共同发布《数字办公安全创新方案》
- 深圳市商务局2022年度中央资金(跨境电子商务企业市场开拓扶持事项)申报指南
- 在码云拉取代码后,调整了seata版本1.5.2。出现如下异常。是因为数据库表缺少字段导致的吗?
- 2022 Strong Net Cup CTF---Strong Net Pioneer ASR wp
猜你喜欢

C#中关于DevExpress的常用操作和帮助类项目工程内容说明

素域和扩域

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

Flask框架实战

完全背包问题求组合数和排列数

05 doris 集群搭建

谁还敢买影视股?

RecSys'22|CARCA: Cross-Attention-Aware Context and Attribute Recommendations
![[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](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[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

MySQL加锁案例分析
随机推荐
好家伙,公司服务器直接热崩掉了!
银行案例|Zabbix跨版本升级指南,4.2-6.0不香吗?
C# LibUsbDotNet 在USB-CDC设备的上位机应用
面对营销难,有米云指出一条破局之路
京东软件测试面试题,仅30题就已经拯救了50%的人
在码云拉取代码后,调整了seata版本1.5.2。出现如下异常。是因为数据库表缺少字段导致的吗?
TCP百万并发服务器优化调参
【硬核拆解】50块2个的2022年夏季款智能节电器到底能不能省电?
云商店携手快报税,解锁财务服务新体验!
11 一发布就发布一系列系列
表达式;运算符,算子;取余计算;运算符优先顺序
短剧正在抢长剧的生意
我的新书销量1万册了!
机器学习快速入门
网上开户佣金万一靠谱吗,网上开户安全吗
The untiy Resources directory dynamically loads resources
zabbix部署和简单使用
C语言:表达式求值详解
70后夫妻给苹果华为做“雨衣”,三年进账7.91亿
Are online account opening commissions reliable? Is online account opening safe?