Linux命令日日说(二十二)-- nl

nl

语法

nl [options] files

为文件里每一行加上行号。


参数

  • -b | --body-numbering=STYLE 设定内容的编号方式,默认方式为t(只有非空白行才有编号)。

  • -d | --section-delimiter=CC 设定逻辑分隔符CC

  • -f | --footer-number=SYTLE 设定页脚的编号方式,默认方式为n

  • -h | --header-number=STYLE 设定页眉的编号方式,默认方式n

  • -i | --line-increment=NUM 设定每行行号增量值。

  • -l | --join-blank-lines=NUM 将指定的一组空行数标记为一行。当STYLEa时有效。

  • -n | --number-format=FORMAT 按照FORMAT格式插入行号。

  • -p | --no-renumber 不重置每个部分的行号。

  • -s | --number-separator=STRING 在行号后添加STRING内容

  • -v | --starting-line-number=NUMBER 首行起始编号。

  • -w | --number-width=NUMBER 设定行号的左缩进宽度。

  • --help 显示帮助信息。

  • --version 显示版本。

STYLE可以定义为:

  • a 全部编号,包括空白行。

  • t 只编号非空白行。

  • n 完全不编号。

  • pREGEXP 只有匹配正则表达式的行才编号。


Example

  • nl LICENSE-2.0.txt

    一般表示行号,不包含空行。

    root@3b4e07cd9fdd:/# nl LICENSE-2.0.txt
    
     1                                   Apache License
     2                             Version 2.0, January 2004
     3                          http://www.apache.org/licenses/
    
     4     TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    
     5     1. Definitions.
    
     6        "License" shall mean the terms and conditions for use, reproduction,
     7        and distribution as defined by Sections 1 through 9 of this document.
    
     8        "Licensor" shall mean the copyright owner or entity authorized by
     9        the copyright owner that is granting the License.
    
    10        "Legal Entity" shall mean the union of the acting entity and all
    11        other entities that control, are controlled by, or are under common
    12        control with that entity. For the purposes of this definition,
    13        "control" means (i) the power, direct or indirect, to cause the
    14        direction or management of such entity, whether by contract or
    15        otherwise, or (ii) ownership of fifty percent (50%) or more of the
    16        outstanding shares, or (iii) beneficial ownership of such entity.
    
    17        "You" (or "Your") shall mean an individual or Legal Entity
    18        exercising permissions granted by this License.
    
    19        "Source" form shall mean the preferred form for making modifications,
    20        including but not limited to software source code, documentation
    21        source, and configuration files.
    
    22        "Object" form shall mean any form resulting from mechanical
    23        transformation or translation of a Source form, including but
    24        not limited to compiled object code, generated documentation,
    25        and conversions to other media types.
    
    26        "Work" shall mean the work of authorship, whether in Source or
    27        Object form, made available under the License, as indicated by a
    28        copyright notice that is included in or attached to the work
    29        (an example is provided in the Appendix below).
    
    30        "Derivative Works" shall mean any work, whether in Source or Object
    31        form, that is based on (or derived from) the Work and for which the
    32        editorial revisions, annotations, elaborations, or other modifications
    33        represent, as a whole, an original work of authorship. For the purposes
    34        of this License, Derivative Works shall not include works that remain
    35        separable from, or merely link (or bind by name) to the interfaces of,
    36        the Work and Derivative Works thereof.
    
    37        "Contribution" shall mean any work of authorship, including
    38        the original version of the Work and any modifications or additions
    39        to that Work or Derivative Works thereof, that is intentionally
    40        submitted to Licensor for inclusion in the Work by the copyright owner
    41        or by an individual or Legal Entity authorized to submit on behalf of
    42        the copyright owner. For the purposes of this definition, "submitted"
    43        means any form of electronic, verbal, or written communication sent
    44        to the Licensor or its representatives, including but not limited to
    45        communication on electronic mailing lists, source code control systems,
    46        and issue tracking systems that are managed by, or on behalf of, the
    47        Licensor for the purpose of discussing and improving the Work, but
    48        excluding communication that is conspicuously marked or otherwise
    49        designated in writing by the copyright owner as "Not a Contribution."
    
    ...
    
    140     9. Accepting Warranty or Additional Liability. While redistributing
    141        the Work or Derivative Works thereof, You may choose to offer,
    142        and charge a fee for, acceptance of support, warranty, indemnity,
    143        or other liability obligations and/or rights consistent with this
    144        License. However, in accepting such obligations, You may act only
    145        on Your own behalf and on Your sole responsibility, not on behalf
    146        of any other Contributor, and only if You agree to indemnify,
    147        defend, and hold each Contributor harmless for any liability
    148        incurred by, or claims asserted against, such Contributor by reason
    149        of your accepting any such warranty or additional liability.
    
    150     END OF TERMS AND CONDITIONS
    
    151     APPENDIX: How to apply the Apache License to your work.
    
    152        To apply the Apache License to your work, attach the following
    153        boilerplate notice, with the fields enclosed by brackets "[]"
    154        replaced with your own identifying information. (Don't include
    155        the brackets!)  The text should be enclosed in the appropriate
    156        comment syntax for the file format. We also recommend that a
    157        file or class name and description of purpose be included on the
    158        same "printed page" as the copyright notice for easier
    159        identification within third-party archives.
    
    160     Copyright [yyyy] [name of copyright owner]
    
    161     Licensed under the Apache License, Version 2.0 (the "License");
    162     you may not use this file except in compliance with the License.
    163     You may obtain a copy of the License at
    
    164         http://www.apache.org/licenses/LICENSE-2.0
    
    165     Unless required by applicable law or agreed to in writing, software
    166     distributed under the License is distributed on an "AS IS" BASIS,
    167     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    168     See the License for the specific language governing permissions and
    169     limitations under the License.
    
  • nl -i 2 LICENSE-2.0.txt

    行号递增数为2.

    root@3b4e07cd9fdd:/# nl -i 2 LICENSE-2.0.txt
    
     1                                   Apache License
     3                             Version 2.0, January 2004
     5                          http://www.apache.org/licenses/
    
     7     TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
    
     9     1. Definitions.
    
    11        "License" shall mean the terms and conditions for use, reproduction,
    13        and distribution as defined by Sections 1 through 9 of this document.
    
    15        "Licensor" shall mean the copyright owner or entity authorized by
    17        the copyright owner that is granting the License.
    ...
    
    
  • nl -b a test.txt

    标记所有行,包含空行。

    root@3b4e07cd9fdd:/# nl -b a test.txt
     1  line1
     2  line2
     3
     4
     5
     6
     7  line3
     8  line4
    
  • nl -b a -l 4 test.txt

    将4行空行为一组标示为一行。

    root@3b4e07cd9fdd:/# nl -b a -l 4 test.txt
     1  line1
     2  line2
    
    
    
     3
     4  line3
     5  line4
    
  • nl -s ". " test.txt

    在行号后面添加.

    root@3b4e07cd9fdd:/# nl -s ". " test.txt
     1. line1
     2. line2
    
    
    
    
     3. line3
     4. line4
    
  • nl -d "00" -b a test.txt

    分割内容标记。

    root@3b4e07cd9fdd:/# nl -d "00" -b a test.txt
     1  line1
     2  line2
     3
     4
    
    
       line3
       line4
    
  • nl -v 3 test.txt

    设定起始标号。

    root@3b4e07cd9fdd:/# nl -v 3 test.txt
     3  line1
     4  line2
    
    
     5  00
    
     6  line3
     7  line4
    
  • nl -w 20 test.txt

    设定标号的宽度。

    root@3b4e07cd9fdd:/# nl -w 20 test.txt
                   1    line1
                   2    line2
    
    
                   3    00
    
                   4    line3
                   5    line4
    
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,186评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,858评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 158,620评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,888评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,009评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,149评论 1 291
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,204评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,956评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,385评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,698评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,863评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,544评论 4 335
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,185评论 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,899评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,141评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,684评论 2 362
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,750评论 2 351

推荐阅读更多精彩内容