MYSYSAD.COM

Display Line Numbers for a File to STDOUT

· Shell & text · Files & disks

The UNIX nl utility displays the line numbers for a file to standard output. It can useful during a debugging session. If you use the nl command without options, it does not show line numbers for the blank lines.

Without options
# nl sysad.txt
1 This blog's
2 content
3 is primarily
4 a HOWTO for UNIX
5 system administration.
6 Its articles consist of Solaris,
7 Sybase, Oracle, and miscellaneous
8 tips and operating system information.

9 This blog's content
10 is primarily
11 a HOWTO for UNIX
12 system administration.
13 Its articles consist of Solaris,
14 Sybase, Oracle, and miscellaneous
15 tips and operating system information.

Show the blank line with a line number
# nl -ba sysad.txt
1 This blog's
2 content
3 is primarily
4 a HOWTO for UNIX
5 system administration.
6 Its articles consist of Solaris,
7 Sybase, Oracle, and miscellaneous
8 tips and operating system information.
9
10 This blog's content
11 is primarily
12 a HOWTO for UNIX
13 system administration.
14 Its articles consist of Solaris,
15 Sybase, Oracle, and miscellaneous
16 tips and operating system information.

Print the numbered output
# nl -ba sysad.txt | lp