Skip to content

nl | Cheatsheet


Use NUMBER columns for line numbers

seq 10|nl --number-width=5

Number separator

seq 10 |nl --number-separator='> '

Body numbering style

echo -e "one\ntwo\n\nfour" | nl -b a
nl -h n -f n filename

Use custom section delimiters

echo -e "one\n%\ntwo\n%\nthree" | nl -d '%'

Example usage

find site/incoming/ -type d -iname *linux* |grep -v '_' |sort|sed 's:.*/::'|nl --number-width=4 --number-separator=") "

Number all lines

seq 10 | nl -b a

Number only nonempty lines (default behavior)

echo -e "one\ntwo\n\nfour" | nl -b t

Number no lines

seq 10 | nl -b n

Number only lines that match a regular expression

echo -e "apple\norange\nbanana\ngrape" | nl -b p'ap'

Section delimiter

echo -e "one\n%\ntwo\n%\nthree" | nl -d '%'
echo -e "one\n%\ntwo\n%\nthree" | nl -f a

Header numbering style

echo -e "one\n%\ntwo\n%\nthree" | nl -h a

Line increment

seq 10 | nl -i 2

Join blank lines

echo -e "one\n\n\ntwo\n\n\nthree" | nl -l 2

Number format

Left justified, no leading zeros

seq 10 | nl -n ln

Right justified, no leading zeros (default behavior)

seq 10 | nl -n rn

Right justified, leading zeros

seq 10 | nl -n rz

No renumber

echo -e "one\n%\ntwo\n%\nthree" | nl -p

Number separator

seq 10 | nl -s '-> '

Starting line number

seq 10 | nl -v 5

Number width

seq 10 | nl -w 3

Version information

nl --version