1NL(1P) POSIX Programmer's Manual NL(1P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
11
13 nl — line numbering filter
14
16 nl [−p] [−b type] [−d delim] [−f type] [−h type] [−i incr] [−l num]
17 [−n format] [−s sep] [−v startnum] [−w width] [file]
18
20 The nl utility shall read lines from the named file or the standard
21 input if no file is named and shall reproduce the lines to standard
22 output. Lines shall be numbered on the left. Additional functionality
23 may be provided in accordance with the command options in effect.
24
25 The nl utility views the text it reads in terms of logical pages. Line
26 numbering shall be reset at the start of each logical page. A logical
27 page consists of a header, a body, and a footer section. Empty sections
28 are valid. Different line numbering options are independently available
29 for header, body, and footer (for example, no numbering of header and
30 footer lines while numbering blank lines only in the body).
31
32 The starts of logical page sections shall be signaled by input lines
33 containing nothing but the following delimiter characters:
34
35 ┌───────────┬────────────┐
36 │ Line │ Start of │
37 ├───────────┼────────────┤
38 │\:\:\: │ Header │
39 │\:\: │ Body │
40 │\: │ Footer │
41 └───────────┴────────────┘
42 Unless otherwise specified, nl shall assume the text being read is in a
43 single logical page body.
44
46 The nl utility shall conform to the Base Definitions volume of
47 POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines. Only one file
48 can be named.
49
50 The following options shall be supported:
51
52 −b type Specify which logical page body lines shall be numbered. Rec‐
53 ognized types and their meaning are:
54
55 a Number all lines.
56
57 t Number only non-empty lines.
58
59 n No line numbering.
60
61 pstring Number only lines that contain the basic regular
62 expression specified in string.
63
64 The default type for logical page body shall be t (text lines
65 numbered).
66
67 −d delim Specify the delimiter characters that indicate the start of a
68 logical page section. These can be changed from the default
69 characters "\:" to two user-specified characters. If only one
70 character is entered, the second character shall remain the
71 default character ':'.
72
73 −f type Specify the same as b type except for footer. The default for
74 logical page footer shall be n (no lines numbered).
75
76 −h type Specify the same as b type except for header. The default
77 type for logical page header shall be n (no lines numbered).
78
79 −i incr Specify the increment value used to number logical page
80 lines. The default shall be 1.
81
82 −l num Specify the number of blank lines to be considered as one.
83 For example, −l 2 results in only the second adjacent blank
84 line being numbered (if the appropriate −h a, −b a, or −f a
85 option is set). The default shall be 1.
86
87 −n format Specify the line numbering format. Recognized values are: ln,
88 left justified, leading zeros suppressed; rn, right justi‐
89 fied, leading zeros suppressed; rz, right justified, leading
90 zeros kept. The default format shall be rn (right justified).
91
92 −p Specify that numbering should not be restarted at logical
93 page delimiters.
94
95 −s sep Specify the characters used in separating the line number and
96 the corresponding text line. The default sep shall be a
97 <tab>.
98
99 −v startnum
100 Specify the initial value used to number logical page lines.
101 The default shall be 1.
102
103 −w width Specify the number of characters to be used for the line num‐
104 ber. The default width shall be 6.
105
107 The following operand shall be supported:
108
109 file A pathname of a text file to be line-numbered.
110
112 The standard input shall be used if no file operand is specified, and
113 shall be used if the file operand is '−' and the implementation treats
114 the '−' as meaning standard input. Otherwise, the standard input shall
115 not be used. See the INPUT FILES section.
116
118 The input file shall be a text file.
119
121 The following environment variables shall affect the execution of nl:
122
123 LANG Provide a default value for the internationalization vari‐
124 ables that are unset or null. (See the Base Definitions vol‐
125 ume of POSIX.1‐2008, Section 8.2, Internationalization Vari‐
126 ables for the precedence of internationalization variables
127 used to determine the values of locale categories.)
128
129 LC_ALL If set to a non-empty string value, override the values of
130 all the other internationalization variables.
131
132 LC_COLLATE
133 Determine the locale for the behavior of ranges, equivalence
134 classes, and multi-character collating elements within regu‐
135 lar expressions.
136
137 LC_CTYPE Determine the locale for the interpretation of sequences of
138 bytes of text data as characters (for example, single-byte as
139 opposed to multi-byte characters in arguments and input
140 files), the behavior of character classes within regular
141 expressions, and for deciding which characters are in charac‐
142 ter class graph (for the −b t, −f t, and −h t options).
143
144 LC_MESSAGES
145 Determine the locale that should be used to affect the format
146 and contents of diagnostic messages written to standard
147 error.
148
149 NLSPATH Determine the location of message catalogs for the processing
150 of LC_MESSAGES.
151
153 Default.
154
156 The standard output shall be a text file in the following format:
157
158 "%s%s%s", <line number>, <separator>, <input line>
159
160 where <line number> is one of the following numeric formats:
161
162 %6d When the rn format is used (the default; see −n).
163
164 %06d When the rz format is used.
165
166 %−6d When the ln format is used.
167
168 <empty> When line numbers are suppressed for a portion of the page;
169 the <separator> is also suppressed.
170
171 In the preceding list, the number 6 is the default width; the −w option
172 can change this value.
173
175 The standard error shall be used only for diagnostic messages.
176
178 None.
179
181 None.
182
184 The following exit values shall be returned:
185
186 0 Successful completion.
187
188 >0 An error occurred.
189
191 Default.
192
193 The following sections are informative.
194
196 In using the −d delim option, care should be taken to escape characters
197 that have special meaning to the command interpreter.
198
200 The command:
201
202 nl −v 10 −i 10 −d \!+ file1
203
204 numbers file1 starting at line number 10 with an increment of 10. The
205 logical page delimiter is "!+". Note that the '!' has to be escaped
206 when using csh as a command interpreter because of its history substi‐
207 tution syntax. For ksh and sh the escape is not necessary, but does
208 not do any harm.
209
211 None.
212
214 None.
215
217 pr
218
219 The Base Definitions volume of POSIX.1‐2008, Chapter 8, Environment
220 Variables, Section 12.2, Utility Syntax Guidelines
221
223 Portions of this text are reprinted and reproduced in electronic form
224 from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
225 -- Portable Operating System Interface (POSIX), The Open Group Base
226 Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
227 cal and Electronics Engineers, Inc and The Open Group. (This is
228 POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
229 event of any discrepancy between this version and the original IEEE and
230 The Open Group Standard, the original IEEE and The Open Group Standard
231 is the referee document. The original Standard can be obtained online
232 at http://www.unix.org/online.html .
233
234 Any typographical or formatting errors that appear in this page are
235 most likely to have been introduced during the conversion of the source
236 files to man page format. To report such errors, see https://www.ker‐
237 nel.org/doc/man-pages/reporting_bugs.html .
238
239
240
241IEEE/The Open Group 2013 NL(1P)