Number lines and write files, writes each FILE to standard output, with line numbers added to some or all of the lines.
If no input file (or '-' ) is given nl will read from standard input.

      nl [options]... [File]...


     Select the numbering style for lines in the body section of each
     logical page.  When a line is not numbered, the current line number
     is not incremented, but the line number separator character is
     still prepended to the line.  
     The styles are:

     'a'          number all lines,

     't'          number only nonempty lines (default for body),

     'n'          do not number lines (default for header and footer),

     'pREGEXP'    number only lines that contain a match for REGEXP.

-d CD
     Set the section delimiter characters to CD; default is '\:'. If
     only C is given, the second remains ':'.  (Remember to protect '\'
     or other metacharacters from shell expansion with quotes or extra

     Specify the same as -b type except for logical page footer lines.
     The default type for logical page footer lines is n.

     Specify the same as -b type except for logical page header lines.
     The default type for logical page header lines is n.

     Increment line numbers by INCR (default 1).

     If numbering of all lines is specified for the current logical section using the
     corresponding -b a, -f a or -h a option, specify the number of adjacent blank lines
     to be considered as one. For example, -l 2 results in only the second adjacent
     blank line being numbered. The default num value is 1.  Where fewer than NUMBER 
     consecutive empty lines occur, do not number them.  An empty line is one that
     contains no characters, not even spaces or tabs.

     Select the line numbering format (default is 'rn'):

    'ln'     left justified, no leading zeros;

    'rn'     right justified, no leading zeros;

    'rz'     right justified, leading zeros.

     Do not reset the line number at the start of a logical page.

-s SEP
     Separate the line number from the text line in the output with
     SEP (default is the TAB character).

     Set the initial line number on each logical page to NUMBER
     (default 1).

     Use NUMBER characters for line numbers (default 6).

'nl' decomposes its input into (logical) pages; by default, the line number is reset to 1 at the top of each logical page.

'nl' treats all of the input files as a single document; it does not reset line numbers or logical pages between files.

A logical page consists of three sections: header, body, and footer. Any of the sections can be empty. Each can be numbered in a different style from the others.

The beginnings of the sections of logical pages are indicated in the input file by a line containing exactly one of these delimiter strings:
\:\:\: start of header;
\:\: start of body;
\: start of footer.
The two characters from which these strings are made can be changed from \ and : via options (see above), but the pattern and length of each string cannot be changed. A section delimiter is replaced by an empty line on output.

Any text that comes before the first section delimiter string in the input file is considered to be part of a body section, so 'nl' treats a file that contains no section delimiters as a single body section.

"Seek not the favor of the multitude; it is seldom got by honest and lawful means. But seek the testimony of few; and number not voices, but weigh them” ~ Immanuel Kant

Related macOS commands

comm - Compare two sorted files line by line.
csplit - Split a file into context-determined pieces.
expand - Convert tabs to spaces.
seq - Print numeric sequences.

Copyright © 1999-2024
Some rights reserved