当前位置:网站首页>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::入门边栏推荐
猜你喜欢

04 flink 集群搭建

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

Sftp中文件名乱码

短剧正在抢长剧的生意

统信软件、龙芯中科等四家企业共同发布《数字办公安全创新方案》

How to Efficiently Develop Jmix Extension Components

04 flink cluster construction

MySQL加锁案例分析

不需要写代码,快速批量修改文件夹中图片的格式

The site is not found after the website is filed. You have not bound this domain name or IP to the corresponding site! The configuration file does not take effect!
随机推荐
Xingtu has been short of disruptive products?Will this M38T from the Qingdao factory be a breakthrough?
直播app开发,是优化直播体验不得不关注的两大指标
The anxiety of the post-90s was cured by the vegetable market
完全背包问题求组合数和排列数
ROS2系列知识(7):用rqt_console查看日志logs
PAT 甲级 A1030 Travel Plan
ROS2系列知识(6):Action服务概念
Live tonight!
云商店携手快报税,解锁财务服务新体验!
Description of common operations and help projects about DevExpress in C#
【R语言】线性混合模型进行重复测量设计分析
OneFlow源码解析:Op、Kernel与解释器
工业制造行业的低代码开发平台思维架构图
02 es cluster construction
京东软件测试面试题,仅30题就已经拯救了50%的人
When custom annotations implement log printing, specific fields are blocked from printing
hcip第九天
【硬核拆解】50块2个的2022年夏季款智能节电器到底能不能省电?
14年测试人最近的面试经历,值得借鉴√
ROS2支持技术:DDS简述