NL(1POSIX)

πŸ’… PROLOG πŸ’…

Okay bestie, real talk before we get into it: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go check the corresponding Linux manual page for the deets on Linux behavior), or β€” plot twist β€” the interface may not even be implemented on Linux at all. πŸ™ˆ


✨ NAME ✨

nl β€” the line numbering filter, and yes she is that girl.

πŸŽ€ 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 you didn't name one β€” and reproduces those lines to standard output. Lines get numbered on the left. Extra functionality may be provided depending on which command options are in effect. Slay.

The way nl thinks about your text is in terms of logical pages. Line numbering gets reset at the start of every logical page. A logical page is made of three parts: a header, a body, and a footer section. Empty sections are totally valid, no drama. And here's the iconic part: header, body, and footer each get their own independent line numbering options. Like, you could have no numbering on header and footer lines while only numbering blank lines in the body. Main character behavior fr.

The starts of logical page sections get signaled by input lines that contain nothing but these delimiter characters:

  • \:\:\: β€” start of Header
  • \:\: β€” start of Body
  • \: β€” start of Footer

Unless you say otherwise, nl shall assume the text it's reading is in a single logical page body. Default vibe.

πŸ’– OPTIONS πŸ’–

nl 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:

  • -b type β€” 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).
  • -d delim β€” 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 you only enter one character, the second character shall remain the default character ':'.
  • -f type β€” Same as b type except for the footer. The default for logical page footer shall be n (no lines numbered).
  • -h type β€” Same as b type except for the header. The default type for logical page header shall be n (no lines numbered).
  • -i incr β€” Specify the increment value used to number logical page lines. The default shall be 1.
  • -l num β€” Specify the number of blank lines to be considered as one. For example, -l 2 results in only the second adjacent blank line being numbered (if the appropriate -h a, -b a, or -f a option is set). The default shall be 1.
  • -n format β€” Specify the line numbering format. 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 be rn (right justified).
  • -p β€” Specify that numbering should not be restarted at logical page delimiters.
  • -s sep β€” Specify the characters used in separating the line number and the corresponding text line. The default sep shall be a <tab>.
  • -v startnum β€” Specify the initial value used to number logical page lines. The default shall be 1.
  • -w width β€” Specify the number of characters to be used for the line number. The default width shall be 6.

🌸 OPERANDS 🌸

The following operand shall be supported:

  • file β€” A pathname of a text file to be line-numbered. Give her a file, she'll give you numbers.

🌈 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 for the receipts.

πŸ“ INPUT FILES πŸ“

The input file shall be a text file. Periodt.

πŸ‘‘ 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. She's the boss.
  • 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 class graph (for the -b t, -f t, and -h t options).
  • 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 of LC_MESSAGES.

🧚 ASYNCHRONOUS EVENTS 🧚

Default. Nothing spicy here, bestie.

⭐ 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 the rn format is used (the default; see -n).
  • %06d β€” When the rz format is used.
  • %-6d β€” When the ln format 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. She's adjustable, we love that.

πŸ’œ STDERR πŸ’œ

The standard error shall be used only for diagnostic messages. That's it, that's the whole job.

πŸ”₯ OUTPUT FILES πŸ”₯

None.

πŸ’€ EXTENDED DESCRIPTION πŸ’€

None. (Iconic of her honestly.)

πŸ’… EXIT STATUS πŸ’…

The following exit values shall be returned:

  • 0 β€” Successful completion. Ate, no notes.
  • >0 β€” An error occurred. 😭

🫢 CONSEQUENCES OF ERRORS 🫢

Default.

The following sections are informative.

πŸŽ€ APPLICATION USAGE πŸŽ€

When you're using the -d delim option, please be careful and escape characters that have special meaning to the command interpreter. That's the whole tip. Protect your delimiters, protect your peace.

🌸 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. So like, escape it anyway, it's cute and harmless. πŸ’–

🌈 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

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 🫢 this was IEEE / The Open Group, 2017, NL(1POSIX) β€” thanks for reading, ily, go number some lines πŸ’…βœ¨

πŸ“¦ where this page comes from