Previous | Table of Contents | Next |
DESCRIPTION
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:
| ||
Section | Input Delimiter | Meaning |
---|---|---|
| ||
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.
COMMAND FORMAT
Following is the general format of the nl command.
nl [ -btype ] [ -ddelim ] [ -ftype ] [ -htype ] [ -iincr ] [ -lnum ] \ [ -nformat ] [ -p ] [ -ssep ] [ -vstart ] [ -wwidth ] [ file ]
Options
The following list describes the options and their arguments that may be used to control how nl functions.
-b type | 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: | |
Type | Function | |
a | Number all lines. | |
n | Do not number the lines. | |
p string | Number only the lines containing the regular expression string. | |
t | Number only lines containing ASCII text that can be displayed on your terminal screen. | |
-d delim | 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. | |
-f type | 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. | |
-h type | 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. | |
-i incr | The number incr is used to increment the line numbers. Normally, the line numbers are incremented by 1. | |
-l n | Considers n blank input lines as one output line. Numbers every n th blank line in a group of adjacent blank lines. The -ha, - ba, and/or -fa options must be specified. | |
-n format | Specifies the format used to display the line numbers. The possible values are: | |
Format | Function | |
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. | |
-s sep | Use string sep to separate the line numbers from the text. The default is a tab. | |
-v start | Use the value of start to begin line numbers. Normally, line numbers start at 1. | |
-w width | The field width for the line numbers is set to width positions . If no value is specified 6 is used. |
Arguments
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. |
RELATED COMMANDS
Refer to the pr command described in Module 105.
APPLICATIONS
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.
TYPICAL OPERATION
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 |