NL(1P)
π PROLOG π
okay so this is a page from the POSIX Programmer's Manual, bestie. fair warning: the Linux version of this interface might be a little different (so go check the matching Linux man page if u need the deets), or honestly it might not even be implemented on Linux at all. no cap. π
β¨ NAME β¨
nl β the line numbering filter, aka the glow-up your text file has been waiting for π
π SYNOPSIS π
nl [-p] [-b type] [-d delim] [-f type] [-h type] [-i incr] [-l num]
[-n format] [-s sep] [-v startnum] [-w width] [file]
πΈ DESCRIPTION πΈ
So nl reads lines from the named file, or from standard input if u didn't name a file, and then it reproduces all those lines to standard output. The lines get numbered on the left. Depending on which command options are in effect, extra functionality may be provided. iconic behavior honestly.
Here's the thing β nl doesn't just see your text as a sad flat pile of lines. It views the text it reads in terms of logical pages. And the line numbering gets reset at the start of each logical page. Every logical page is made of three parts: a header, a body, and a footer section. Empty sections are totally valid, no judgment. And here's the slay part: different line numbering options are independently available for header, body, and footer. Like for example β no numbering of header and footer lines, while numbering blank lines only in the body. mix and match, bestie π
The starts of those logical page sections are signaled by input lines that contain nothing but the following delimiter characters:
\:\:\:β start of Header\:\:β start of Body\:β start of Footer
And unless u say otherwise, nl is gonna assume the text it's reading is all in a single logical page body. periodt.
β¨ OPTIONS β¨
The nl utility shall conform to the Base Definitions volume of POSIX.1β2017, Section 12.2, Utility Syntax Guidelines. Only one file can be named, so don't get greedy.
The following options shall be supported:
-btype β Specify which logical page body lines shall be numbered. The recognized types and their meaning are:aβ number all lines.tβ number only non-empty lines.nβ no line numbering.pstringβ number only lines that contain the basic regular expression specified in string.- The default type for logical page body shall be
t(text lines numbered). π«Ά
-ddelim β Specify the delimiter characters that indicate the start of a logical page section. These can be changed from the default characters"\:"to two user-specified characters. If only one character is entered, the second character shall remain the default character':'.-ftype β Specify the same as b type except for the footer. The default for logical page footer shall ben(no lines numbered).-htype β Specify the same as b type except for the header. The default type for logical page header shall ben(no lines numbered).-iincr β Specify the increment value used to number logical page lines. The default shall be1.-lnum β Specify the number of blank lines to be considered as one. For example,-l 2results in only the second adjacent blank line being numbered (if the appropriate-h a,-b a, or-f aoption is set). The default shall be1.-nformat β Specify the line numbering format. The recognized values are:ln, left justified, leading zeros suppressed;rn, right justified, leading zeros suppressed;rz, right justified, leading zeros kept. The default format shall bern(right justified).-pβ Specify that numbering should not be restarted at logical page delimiters.-ssep β Specify the characters used in separating the line number and the corresponding text line. The default sep shall be a<tab>.-vstartnum β Specify the initial value used to number logical page lines. The default shall be1.-wwidth β Specify the number of characters to be used for the line number. The default width shall be6.
π¦ OPERANDS π¦
The following operand shall be supported:
- file β A pathname of a text file to be line-numbered.
π STDIN π
The standard input shall be used if no file operand is specified, and shall be used if the file operand is '-' and the implementation treats the '-' as meaning standard input. Otherwise, the standard input shall not be used. See the INPUT FILES section.
π INPUT FILES π
The input file shall be a text file.
π ENVIRONMENT VARIABLES π
The following environment variables shall affect the execution of nl:
LANGβ Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of POSIX.1β2017, Section 8.2, Internationalization Variables for the precedence of internationalization variables used to determine the values of locale categories.)LC_ALLβ If set to a non-empty string value, override the values of all the other internationalization variables.LC_COLLATEβ Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regular expressions.LC_CTYPEβ Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multi-byte characters in arguments and input files), the behavior of character classes within regular expressions, and for deciding which characters are in character classgraph(for the-b t,-f t, and-h toptions).LC_MESSAGESβ Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.NLSPATHβ Determine the location of message catalogs for the processing ofLC_MESSAGES.
β ASYNCHRONOUS EVENTS β
Default.
π§ STDOUT π§
The standard output shall be a text file in the following format:
"%s%s%s", <line number>, <separator>, <input line>
where <line number> is one of the following numeric formats:
%6dβ When thernformat is used (the default; see-n).%06dβ When therzformat is used.%-6dβ When thelnformat is used.<empty>β When line numbers are suppressed for a portion of the page; the<separator>is also suppressed.
In the preceding list, the number 6 is the default width; the -w option can change this value.
π STDERR π
The standard error shall be used only for diagnostic messages.
π OUTPUT FILES π
None.
π EXTENDED DESCRIPTION π
None.
π EXIT STATUS π
The following exit values shall be returned:
0β Successful completion.>0β An error occurred.
π CONSEQUENCES OF ERRORS π
Default.
The following sections are informative.
π«Ά APPLICATION USAGE π«Ά
In using the -d delim option, care should be taken to escape characters that have special meaning to the command interpreter. (yes this is a real warning, do not skip it bestie π₯²)
π₯ EXAMPLES π₯
The command:
nl -v 10 -i 10 -d \!+ file1
numbers file1 starting at line number 10 with an increment of 10. The logical page delimiter is "!+". Note that the '!' has to be escaped when using csh as a command interpreter because of its history substitution syntax. For ksh and sh the escape is not necessary, but does not do any harm.
πΈ RATIONALE πΈ
None.
π FUTURE DIRECTIONS π
None.
β¨ SEE ALSO β¨
pr- The Base Definitions volume of POSIX.1β2017, Chapter 8, Environment Variables, Section 12.2, Utility Syntax Guidelines
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page, bestie!! IEEE/The Open Group, 2017, NL(1P) β go forth and number ur lines, u absolute icon πβ¨
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms