(reprint) The Linux command of the XI. NL command __linux

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 the file contents of the output to the line number.   The default result is a bit different from the cat-n, and NL can do more display design of the line number, including the number of digits and whether the automatic completion of 0 and so on. 1. Command format:

NL [Options] ... [File] ... 2. Command parameters:

-B: Specifies the way the line number is specified, there are two main types:

-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 you have a blank line, do not list the line number (default) for the empty line;

-N: Lists the methods that are represented by line numbers, with three main types:

-N LN: line numbers are displayed at the left of the screen;

-N RN: The line number is displayed at the right of its own field, and does not add 0;

-N RZ: The line number is displayed on the right-hand side of its field, plus 0;

-W: The number of bits 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), calculates the line number in the input, and writes the calculated line number to the standard output. In the output, the NL command calculates the left row 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, body, and footer section (you can have an empty section). Unless the-p flag is used, the NL command will reset the line number at the beginning of each logical page. You can set line calculation flags for header, body, and footer sections individually (for example, header and footer rows can be computed but text lines cannot). 4. Use instance:

Example One: List the contents of Log2012.log in NL

Command:

NL Log2012.log

Output:

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

     3  ======[root@localhost test]#
Description: Blank lines in the file, NL does not add line numbers

Example Two: the content of Log2012.log is listed in NL, and the line number is also added to the blank

Command:

Nl-b a Log2012.log

Output:

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

example three: Make line number before automatically fill 0, unified output format

Output:

[Root@localhost test]# nl-b a-n rz log2014.log 
000001  2014-01 000002 2014-02 000003 2014-03
000004  2014-04
000005  2014-05
000006
2014-06 000007  2014-07
000008  2014-08
000009  2014-09  000010
2014-10 000011 2014-11 000012  2014-12
000013  =======
[Root@localhost test]# nl-b a-n rz-w 3 log2014.log 
001     2014-01
002 2014-02 003     2014-03
004     2014-04
005     2014-05
006     2014-06     007 2014-07 008 2014-08
009     2014-09
010     2014-10
011     2014-11     012 2014-12 013 =======
Description: nl-b a-n RZ command line number defaults to six-bit, to adjust the number of digits can be added with the parameter-W 3 adjusted to 3 bits.

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.