Common Linux commands (10) and common Linux commands (

Source: Internet
Author: User

Common Linux commands (10) and common Linux commands (

The nl command is used in linux to calculate the row number in the file. Nl can automatically add the row number to the output file content! The default result is a little different from cat-n. nl can compare multiple display designs of the row number, including the number of digits and whether to automatically complete 0.


1.Command Format:

Nl [Option]... [file]...


2.Command parameters:

-B: Specifies the row number in two ways:

-B a: indicates that the row number (similar to cat-n) is also listed no matter whether the row is empty or not );

-B t: if there is a blank row, do not list the row number (default) for the empty row );

-N: Used to list row numbers. There are three methods:

-N ln: the row number is displayed on the leftmost side of the screen;

-N rn: the row number is displayed on the rightmost side of its own column without 0;

-N rz: the row number is displayed on the rightmost side of its own column with a value of 0;

-W: The number of digits occupied by the row number column.

-P does not start computing again at the logical delimiters.


3.Command function:

The nl command reads the File parameter (standard input by default), calculates the row number in the input, and writes the computed row number to the standard output. In the output, the nl command calculates the left line based on the flag specified in the command line. The input text must be written on the logic page. Each logic page has a header, body, and footer section (you can leave a blank section ). Unless the-p Flag is used, the nl command resets the row number at the beginning of each logic page. You can set a line calculation flag for the header, body, and footer sections separately (for example, the header and footer rows can be calculated, but the text rows cannot ).


4.Instance used:

Instance 1:Use nl to list log2012.log content

Command: nl log2012.log

[root@localhost test]# nl log2012.log      1  2012-01     2  2012-02                   3  ======[root@localhost test]#

Example 2:Use nl to list the content of log2012.log, and add a line number to empty rows.

Command: nl-B a log2012.log

[root@localhost test]# nl -b a log2012.log      1  2012-01     2  2012-02     3     4     5  ======[root@localhost test]#


Example 3:Set 0 in front of the line number to unify the output format.

Command: nl-B a-n rz log2014.log

Note: The default line number of the nl-B a-n rz command is six digits. To adjust the number of digits, you can add the parameter-w 3 to three digits.

[root@localhost test]# nl -b a -n rz log2014.log 000001  2014-01000002  2014-02000003  2014-03000004  =======[root@localhost test]# nl -b a -n rz -w 3 log2014.log 001     2014-01002     2014-02003     2014-03004     =======








Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.