In a Linux system, the NL command is used 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 do a lot of display design, including the number of digits and whether the automatic completion of 0 and other functions.
1. Command format:
NL [Options] ... [File] ...
2. 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: The line number is displayed on the very right of the field, plus 0;
-W: The number of digits occupied by the line number field.
-P does not restart the calculation at the logical delimiter.
command example:
1. Use NL to list the contents of/etc/issue
[[email protected] zdw]# nl/etc/issue 1 CentOS release 6.5 (Final) 2 Kernel \ R on a \m this file actually has three lines and the third action is blank, so NL will not add Upstream number, if you want to add line numbers, you can use the-b a parameter [[email protected] zdw]# nl-b a/etc/issue 1 CentOS release 6.5 (Final) 2 Kernel \ R on an \m 3
2. Let the line number in front of the auto-fill 0
[Email protected] zdw]# nl-b a-n rz/etc/issue000001 CentOS release 6.5 (Final) 000002 Kernel \ r on a \m000003 automatically in its own field Place 0, the default field is 6 digits, if changed to 3 bits, as follows: [[email protected] zdw]# nl-b a-n rz-w 3/etc/issue001 CentOS release 6.5 (Final) 002 Kernel \ r on an \m003
Learn from:
Brother Bird's Linux private cuisine
This article is from the blog "Write to Yourself", so be sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1765332
Linux NL command