nl
nl linux command cheatsheet by Thamizhiniyan C S
Introduction
The nl command is used to number lines of files.
Syntax
nl [OPTION]... [FILE]...
Important Flags
-b STYLE
Used for numbering body lines
-i NUMBER
Line number increment at each line
-n FORMAT
Insert line numbers according to FORMAT
-v NUMBER
Change first line number of the given input
-l NUMBER
Group of NUMBER empty lines are counted as one
-s STRING
Add any STRING after every logical line number
-w NUMBER
Use different NUMBER columns for line numbers
Default Options
-b t -d ':' -f n -h n -i 1 -l 1 -n 'rn' -s -v 1 -w 6
STYLE to be used with Options
a
Number all lines
t
Number only nonempty lines
n
Number no lines
pBRE
Number only lines that contain a match for the basic regular expression, BRE
FORMAT to be used with Options
ln
Left justified, no leading zeros
rn
Right justified, no leading zeros
rz
Right justified, leading zeros
Examples
To display a file with line numbers (Numbers all non-empty lines)
To number all lines (including empty lines also)
Count multiple, consecutive, non-empty lines as one
Override default increment
To make the starting line number different
Add a string literal after line numbers
Change column for line numbers
To number all logical lines that match the specified REGEX (number those lines that begin with F)
To print the lines using left-justified, no leading zeros number format
To print the lines using right-justified, no leading zeros number format
To print the lines using right-justified with leading zeros format
Last updated
Was this helpful?