mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-09 07:24:04 +08:00
66 lines
2.9 KiB
HTML
66 lines
2.9 KiB
HTML
<h1 id="nl">nl</h1>
|
||
<p>在Linux系统中计算文件内容行号</p>
|
||
<h2 id="补充说明">补充说明</h2>
|
||
<p><strong>nl命令</strong> 读取 file 参数(缺省情况下标准输入),计算输入中的行号,将计算过的行号写入标准输出。在输出中,nl命令根据您在命令行中指定的标志来计算左边的行。输入文本必须写在逻辑页中。每个逻辑页有头、主体和页脚节(可以有空节)。除非使用<code>-p</code>选项,nl 命令在每个逻辑页开始的地方重新设置行号。可以单独为头、主体和页脚节设置行计算标志(例如,头和页脚行可以被计算然而文本行不能)。其默认的结果与<code>cat -n</code>有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐0等等的功能。</p>
|
||
<h3 id="语法">语法</h3>
|
||
<pre><code class="language-bash">nl (选项) (参数)</code></pre>
|
||
<h3 id="选项">选项</h3>
|
||
<pre><code class="language-bash">-b :指定行号指定的方式,主要有两种:
|
||
-b a :表示不论是否为空行,也同样列出行号(类似 cat -n);
|
||
-b t :如果有空行,空的那一行不要列出行号(默认值);
|
||
|
||
-n :列出行号表示的方法,主要有三种:
|
||
-n ln :行号在萤幕的最左方显示;
|
||
-n rn :行号在自己栏位的最右方显示,且不加 0 ;
|
||
-n rz :行号在自己栏位的最右方显示,且加 0 ;
|
||
|
||
-w :行号栏位的占用的位数。
|
||
-p :在逻辑定界符处不重新开始计算。</code></pre>
|
||
<h3 id="实例">实例</h3>
|
||
<p><strong>用 nl 列出 log2015.log 的内容</strong> :</p>
|
||
<pre><code class="language-bash">root@localhost [test]# nl log2015.log
|
||
1 2015-01
|
||
2 2015-02
|
||
|
||
3 ======[root@localhost test]#</code></pre>
|
||
<p>说明:文件中的空白行,nl 不会加上行号</p>
|
||
<p><strong>用 nl 列出 log2015.log 的内容,空本行也加上行号</strong> :</p>
|
||
<pre><code class="language-bash">[root@localhost test]# nl -b a log2015.log
|
||
1 2015-01
|
||
2 2015-02
|
||
3
|
||
4
|
||
5 ======[root@localhost test]#</code></pre>
|
||
<p><strong>让行号前面自动补上0,统一输出格式:</strong></p>
|
||
<pre><code class="language-bash">[root@localhost test]# nl -b a -n rz log2015.log
|
||
000001 2015-01
|
||
000002 2015-02
|
||
000003 2015-03
|
||
000004 2015-04
|
||
000005 2015-05
|
||
000006 2015-06
|
||
000007 2015-07
|
||
000008 2015-08
|
||
000009 2015-09
|
||
000010 2015-10
|
||
000011 2015-11
|
||
000012 2015-12
|
||
000013 =======
|
||
|
||
[root@localhost test]# nl -b a -n rz -w 3 log2015.log
|
||
001 2015-01
|
||
002 2015-02
|
||
003 2015-03
|
||
004 2015-04
|
||
005 2015-05
|
||
006 2015-06
|
||
007 2015-07
|
||
008 2015-08
|
||
009 2015-09
|
||
010 2015-10
|
||
011 2015-11
|
||
012 2015-12
|
||
013 =======</code></pre>
|
||
<p>说明:<code>nl -b a -n rz</code>命令行号默认为六位,要调整位数可以加上参数<code>-w 3</code>调整为3位。</p>
|
||
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->
|