Use the --number flag to print line numbers before each line. Alternatively, -n does the same thing.

$ cat --number file

 1  line 1
 2  line 2
 3
 4  line 4
 5  line 5

To skip empty lines when counting lines, use the --number-nonblank, or simply -b.

$ cat -b file

 1  line 1
 2  line 2

 3  line 4
 4  line 5