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
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
Number only nonempty lines (default behavior)
echo -e "one\ntwo\n\nfour" | nl -b t
Number no lines
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
echo -e "one\n%\ntwo\n%\nthree" | nl -h a
Line increment
Join blank lines
echo -e "one\n\n\ntwo\n\n\nthree" | nl -l 2
Left justified, no leading zeros
Right justified, no leading zeros (default behavior)
Right justified, leading zeros
No renumber
echo -e "one\n%\ntwo\n%\nthree" | nl -p
Number separator
Starting line number
Number width