Operating system | Unix andUnix-like |
---|---|
Platform | Cross-platform |
Type | Command |
License | coreutils:GPLv3+ |
nl is aUnix utility for numbering lines, either from a file or from standard input, reproducing output on standard output.
nl
is part of theX/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and theSingle Unix Specification.[1] It first appeared inSystem V release 2.[2]
The version ofnl
bundled inGNUcoreutils was written by Scott Bartram and David MacKenzie.[3]
The command is available as a separate package forMicrosoft Windows as part of theUnxUtils collection ofnativeWin32ports of common GNU Unix-like utilities.[4]
The command has a number of switches:
The default applied switch ist.
nl also supports some command line options.
$nltf1echopresscr2readcr3done
The following example numbers only the lines that begin with a capital letter A (matching on theregular expression /^A/).filename is optional.
$nl-bp^Afilename apple 1 Apple BANANA 2 Allspice strawberry
It can be useful as an alternative togrep -n:
$catsomefileaaaabbbbccccdddc$nlsomefile|grepcccc 3 cccc
nl
– Shell and Utilities Reference,The Single UNIX Specification, Version 4 fromThe Open Groupnl(1)
– FreeBSD General CommandsManualnl(1)
– Linux General CommandsManual