NL---A linux command per day

Source: Internet
Author: User

?? The NL command is used in the Gnu/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 somewhat different from "Cat-n", where NL can do more display design, including the function of the number of digits and whether it is auto-filled 0, and so on.

Use:

?? Calculates the line number of a file.
?? 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).

Command format:

?? NL [Options] ... [File] ...
?? NL [-B type] [-F Type] [-H type] [-l number] [-D Delimiter] [-I number] [-N Format] [-v number] [-W Numbe R] [-p] [-S Separator] [File]

Command parameters:

?? -B: Specifies 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, the empty line does not list the row number (default);
?? -N: List the method of line number representation, there are three main kinds:
???? -N LN: The line number is displayed at the left of the screen;
???? -N RN: The line number is displayed on the very right of its own field and does not add 0;
???? -N RZ: line number in its own field to the right of the display, and add 0;
?? -W: The number of digits occupied by the line number field.
?? -P does not restart the calculation at the logical delimiter.

Example 1: Listing the contents of Minicom.log with NL
[Email protected]:~# nl fan.log  1          20140812 20:46:05 hangup (0:00:00) 2          20140825 18:06:42 hangup (0:00:00) 3
   20140826 10:53:08 Hangup (0:00:00) 4          20140826 15:26:35 hangup (0:00:00) 5          20140827 10:38:00 Hangup (0:00:00) 6< c7/>20140827 18:15:42 Hangup (0:00:00)

?? Description: Blank line in file, NL does not add line number

Example 2: Use Nl-b A to list the contents of the Minicom.log, complement the line number of the blank number
[Email protected]:~# nl-b a fan.log  1          20140812 20:46:05 hangup (0:00:00) 2          20140825 18:06:42 hangup (0:00:00) 3   4   5   6          20140826 10:53:08 hangup (0:00:00) 7          20140826 15:26:35 hangup (0:00:00) 8   9          20140827 10:38:00 hangup (0:00:00)         20140827 18:15:42 hangup (0:00:00)
Example 3: Make the line number preceded by 0, unified output format
[Email protected]:~# nl-b a  -n rz fan.log 000001          20140812 20:46:05 hangup (0:00:00) 000002 20140825 18:06:42          H Angup (0:00:00) 000003  000004  000005  000006          20140826 10:53:08 hangup (0:00:00) 000007          20140826 15:26:35 Hangup (0:00:00) 000008  000009          20140827 10:38:00 hangup (0:00:00) 000010 20140827          18:15:42 Hangup (0:00:00)  [Email protected]:~# nl-b a  -n rz-w 3 fan.log 001 20140812 20:46:05         hangup (0:00:00) 002         20140825 18:06:42 Hangup (0:00:00) 003 004 005 006         20140826 10:53:08 hangup (0:00:00) 007         20140826 15:26:35 hangup (0:00:00) 008 009         20140827 10:38:00 hangup (0:00:00) 010         20140827 18:15:42 hangup (0:00:00)

?? Description: Nl-b a-n RZ the command line number defaults to six bits, to adjust the number of bits can be added to the parameter-W 3 is adjusted to 3 bits.
?? Finally, I only listed a few examples, to give you a point, more multifunctional hope to dig their own. Linux commands one per day, please expect.

NL---A linux command per day

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.