Linux NL--Let the output file content automatically add line number

Source: Internet
Author: User

The NL command is used in a Linux system to calculate the line number of a file. NL can automatically add a line number to the output file content! The default result is a bit different from Cat-n, NL can make the line number more display design, including the number of digits and whether auto-completion 0 and so on.

1. Command format:
NL [Options] ... [File] ...
2. Command parameters:
-B  : Specify the way the line number is specified, mainly in two ways:-B A: Indicates that the line number (similar to cat-N)is also listed, whether or not it is a blank line;-B T: If there is a blank line, do not list the line number (default)for the empty row; N  : List the method of line number representation, there are three main kinds:-N LN: The line number is displayed on the left of the screen;-n RN: The line number is displayed on the right-most side of the field, and does not add 0;-N RZ: The line number is displayed on the very right of its own field, plus 0;-W  : The number of digits occupied by the line number field. -P does not restart the calculation at the logical delimiter.
3. Command function:

The NL command reads the file parameter (standard input by default), computes the line number in the input, and writes the computed line number to standard output. In the output, the NL command calculates the left line based on the flags that you specify on the command line. The input text must be written in a logical page. Each logical page has a header, a body, and a footer section (which can have an empty section). Unless you use the-P flag, the NL command re-sets the line number where each logical page begins. Row calculation flags can be set separately for header, body, and footer sections (for example, header and footer lines can be computed but text lines cannot).

4. Usage Examples:

Example one: List the contents of Log2012.log with NL

Command:nl log2012.log

Output:

[[email protected] test] #      1  2012-01     2  2012-02                   3  ======[[email protected] test]#

Description

Blank lines in the file, NL does not add line numbers

Example two: The contents of Log2012.log are listed in NL, and the line number is also added to the empty bank.

Command:nl-b alog2012.log

Output:

[[email protected] test] #      1  2012-01     2  2012-02     3     4     5  ======[[email protected] test]# 

Example 3: Make the line number preceded by 0, unified output format

Command:nl-b a-n RZ log2014.log

Output:

[[email protected] test] #  000001  2014-01000002  2014-02000003  2014-03000004  2014-04000005  2014-05000006  2014-06000007  2014-07000008  2014-08000009  2014-09000010  2014-10000011  2014-11000012  2014-12000013  =======

Command:nl-b a-n rz-w 3 Log2014.log

Output:

[[email protected] test] #  001     2014-01002     2014-02003     2014-03004     2014-04005     2014-05006     2014-06007     2014-078     2014-08 9     2014-09010     2014-10011     2014-11012     2014-12013     =======

Description

Nl-b a-n RZ the command line number defaults to six bits, and the number of bits to adjust can be adjusted to 3 bits with the parameter-W 3.

Linux NL--Let the output file content automatically add line number

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.