|Previous||Table of Contents||Next|
The external nl command is used to precede input text with line numbers. The input may be a file or the standard input. Special delimiters may be used in the input text to control how nl numbers the lines.
The nl command views the input text as logical pages. There are three possible sections within each logical page. A section of a logical page may be empty. Each section may be numbered differently. The following table lists the strings that separate the logical pages into sections. These strings must be placed in the input data. The sections and their delimiter strings are:
|header||\:\:\:||Marks the beginning of the header section.|
|body||\:\:||Marks the beginning of the body section.|
|footer||\:||Marks the beginning of the footer section.|
If no delimiters exist in the input, nl performs line numbering on the entire file as if it were one logical page consisting of only a body section.
To illustrate the logical page concept let us assume we have the following file:
cj> cat afile \:\:\: The header section \:\: The body section of the file. \: The footer section
This file makes up one logical page for nl to process. The \:\:\: string informs nl that the header section follows. The \:\: string precedes the main body section of the file. And last, the \: sets apart the footer section. Each logical page may contain one or more of these sections. If no section delimiters are found by nl, then all input is considered to be the body section.
Following is the general format of the nl command.
nl [ -btype ] [ -ddelim ] [ -ftype ] [ -htype ] [ -iincr ] [ -lnum ] \ [ -nformat ] [ -p ] [ -ssep ] [ -vstart ] [ -wwidth ] [ file ]
The following list describes the options and their arguments that may be used to control how nl functions.
|-btype||Specifies which lines in the body section are to be numbered based on the given type. The default type of numbering is "t." The available types are:|
|a||Number all lines.|
|n||Do not number the lines.|
|pstring||Number only the lines containing the regular expression string.|
|t||Number only lines containing ASCII text that can be displayed on your terminal screen.|
|-ddelim||Changes the delimiter characters used to break the logical page into sections. The normal characters are \:. You must specify two characters. If you do not, the colon (:) remains as the second default character. No space is allowed between the -d and delim string.|
|-ftype||Specifies which lines in the footer section are to be numbered based on the given type. The default type of numbering is "n." The available types are listed under option -b.|
|-htype||Specifies which lines in the header section are to be numbered based on the given type. The default type of numbering is "n." The available types are listed under option -b.|
|-iincr||The number incr is used to increment the line numbers. Normally, the line numbers are incremented by 1.|
|-ln||Considers n blank input lines as one output line. Numbers every nth blank line in a group of adjacent blank lines. The -ha, - ba, and/or -fa options must be specified.|
|-nformat||Specifies the format used to display the line numbers. The possible values are:|
|ln||Left justify with leading zeroes suppressed.|
|rn||Right justify with leading zeroes suppressed.|
|rz||Right justify with leading zeroes.|
|If no format is specified rn is assumed.|
|-p||The line numbers are not reset for each new logical page. Normally each logical page (not section) begins with line number one.|
|-ssep||Use string sep to separate the line numbers from the text. The default is a tab.|
|-vstart||Use the value of start to begin line numbers. Normally, line numbers start at 1.|
|-wwidth||The field width for the line numbers is set to width positions. If no value is specified 6 is used.|
The following argument may be passed to the nl command.
|file||One file of input data. The nl command can only read from one source of input.|
|If no file is specified, nl reads from the standard input. Therefore, it can be used in pipes.|
Refer to the pr command described in Module 105.
The nl command is designed to provide line numbering for files. It can provide various line numbering methods and is fairly simple to use. One of the most popular uses is numbering lines beginning at a certain number and incrementing the line numbers by a multiple of 10 or 100. It is often used to number the lines on a program listing before sending the listing to the printer.
In this activity you use the nl command to place line numbers before each file listed in the /bin directory. Begin at the shell prompt.
|Previous||Table of Contents||Next|