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 functions:
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. Example:
Example 1: Use NL to list log2012.log content
Command:
NL log2012.log
Output:
[[Email protected] Test] # NL log2012.log
1 2012-01
2 2012-02
3 ====== [[email protected] Test] #
Note:
Empty lines in the file. line numbers are not added to NL.
Example 2: Use NL to list the content of log2012.log, and add a row number to the blank line.
Command:
NL-B A log2012.log
Output:
[[Email protected] Test] # NL-B A log2012.log
1 2012-01
2 2012-02
3
4
5 ====== [[email protected] Test] #
Instance 3: Set 0 to the front of the row number to unify the output format.
Command:
Output:
[[Email protected] 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 ========
[[Email protected] 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 ========
Note:
The default line number of the NL-B A-N RZ command is six digits. To adjust the number of digits, add the parameter-W 3 to three digits.
Address: http://www.cnblogs.com/peida/archive/2012/11/01/2749048.html