The nl command is used on Linux to calculate the line number of a file. It is short for number of lines. Nl can automatically add line numbers to output files! The default is a little different from cat-n, where NL can customize the line number display, including bits and auto-complete zeros.

The command format

Nl [option]... [file]...

The command parameter

The green box marks the display bar, which is 6 digits by default.

  • -b a Lists the line numbers regardless of whether the line is empty
  • -b t Empty lines do not list line numbers (default).
  • The -n ln line number is displayed on the left of the display bar.
  • -n Rn line numbers are displayed at the far right of the display bar without padding 0.
  • -n rz Line numbers are displayed at the far right of the display bar (default).
  • -w Indicates the number of digits occupied by the display column. (Default is 6 digits.)
  • -p does not restart the evaluation at the logical delimiter

Command function

The nl command reads the File argument (standard input by default), calculates the line number in the input, and writes the calculated line number to standard output. In the output, the NL command calculates the left line based on the flags you specify on the command line. The input text must be written in the logical page. Each logical page has a header, body, and footer section (which can be empty). Unless the -p flag is used, the nl command resets the line number at the beginning of each logical page. Line evaluation flags can be set separately for header, body, and footer sections (for example, header and footer lines can be evaluated while text lines cannot).

withnllistrumenz.txtThe line number

> nl rumenz. TXT 1 entry station 2 rumenz 3 ping 4 EntryCopy the code

Empty lines in the file, no line numbers by default

withnllistrumenz.txtThe line number of, including blank lines

> < span style = "box-sizing: border-box; color: RGB (51, 51, 51)Copy the code

The line number is preceded by 0

> NL-b a-n rz rumenz. TXT 000001 Starter station 000002 000003 Rumenz 000004 000005 Ping 000006 000007 StartCopy the code

The default is 6 bits

The line number display column takes up 3 bits and is filled with 0

> nl-b a-n rz-w 3 rumenz. TXT 001 Starter station 002 003 rumenz 004 005 ping 006 007 StarterCopy the code

Use custom number delimiters

> nl-s :: rumenz.txt 1:: entry ministation 2::rumenz 3::ping 4:: entryCopy the code

Original link :rumenz.com/rumenbiji/l… Wechat official account: entry station