Get the App
SLTechnology News&Howtos  ›  Servers  › 

Use the nl command of linux-add line number

Shulou Source: shulou.com Published: 2022-06-02 15:24:25 09月28日 Update

This article will explain in detail the nl command about using linux-adding line numbers, the editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The nl command is an easy to use number filtering tool. This command reads the File parameter (standard input by default), calculates the line number in the input, and writes the calculated line number to standard output.

Syntax format: nl [parameters] [file]

Common parameters:

-b specifies how the line number is specified-n lists how the line number is represented-the number of bits occupied by the w line number field-p does not restart the calculation at the logical delimiter.

Reference example

Use nl to list the contents of log2.log:

[root@linuxcool ~] # nl log2.log

List the contents of the log2.log in nl, and add the line number to the blank line:

[root@linuxcool] # nl-b a log2.log

Let the line number be automatically preceded by 0 to unify the output format:

[root@linuxcool] # nl-b a-n rz log2.log

Blank lines do not display line numbers:

[root@linuxcool] # nl-b t log2.log

The added line number is on the right:

[root@linuxcool~] # nl-n rn log2.log about using linux nl command-add line number to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Line number command content parameter method more standard format article reference input output good practical digit delimiter instance tool commonly used situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft NVidia vpn OPPO Reno Redmi