Nl (Unix)
   HOME

TheInfoList



OR:

nl is a
Unix utility This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on modern ...
for numbering lines, either from a file or from standard input, reproducing output on standard output.


History

is part of the
X/Open X/Open group (also known as the Open Group for Unix Systems and incorporated in 1987 as X/Open Company, Ltd.) was a consortium founded by several European UNIX systems manufacturers in 1984 to identify and promote open standards in the field of info ...
Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the
Single Unix Specification The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
. It first appeared in
System V Unix System V (pronounced: "System Five") is one of the first commercial versions of the Unix operating system. It was originally developed by AT&T and first released in 1983. Four major versions of System V were released, numbered 1, 2, 3, an ...
release 2. The version of nl bundled in
GNU GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
coreutils The GNU Core Utilities or coreutils is a collection of GNU software that implements many standard, Unix-based shell commands. The utilities generally provide POSIX compliant interface when the environment variable is set, but otherwise offers ...
was written by Scott Bartram and David MacKenzie. The command is available as a separate package for
Microsoft Windows Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
as part of the
UnxUtils UnxUtils is a collection of utility programs that provide popular Unix-based shell commands ported from GNU implementations as native Windows programs that depend only on Win32 and the Microsoft C- runtime ( msvcrt.dll). The collection wa ...
collection of
native Native may refer to: People * '' Jus sanguinis'', nationality by blood * '' Jus soli'', nationality by location of birth * Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory ** Nat ...
Win32 The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs can acces ...
ports Ports collections (or ports trees, or just ports) are the sets of makefiles and Patch (Unix), patches provided by the BSD-based operating systems, FreeBSD, NetBSD, and OpenBSD, as a simple method of installing software or creating binary packages. T ...
of common GNU Unix-like utilities.


Syntax

The command has a number of switches: *a - number all lines *t - number lines with printable text only *n - no line numbering *string - number only those lines containing the regular expression defined in the ''string'' supplied. The default applied switch is ''t''. nl also supports some command line options.


Example

$ nl tf 1 echo press cr 2 read cr 3 done The following example numbers only the lines that begin with a capital letter A (matching on the
regular expression A regular expression (shortened as regex or regexp), sometimes referred to as rational expression, is a sequence of characters that specifies a match pattern in text. Usually such patterns are used by string-searching algorithms for "find" ...
/^A/). ''filename'' is optional. $ nl -b p^A filename apple 1 Apple BANANA 2 Allspice strawberry It can be useful as an alternative to : $ cat somefile aaaa bbbb cccc dddc $ nl somefile , grep cccc 3 cccc


See also

*
wc (Unix) (short for word count) is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count ...
– the word count command *
cat (Unix) cat is a shell command for writing the content of a file or input stream to standard output. The name is an abbreviation of ''concatenate'' which is from the Latin ''catenare'' meaning "to chain" Originally developed for Unix, it is available o ...
– concatenate command (-n flag is equivalent to nl -a) *
List of Unix commands This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...


References


External links

{{Core Utilities commands Unix text processing utilities Unix SUS2008 utilities