How can I prepend a line number and tab to each line of a text file?

How can I append a line number and tab to the beginning of each line of a text file?


Solution 1:

awk '{printf "%d\t%s\n", NR, $0}' < filename

Solution 2:

The nl command should do this, but it adds space before the line number too. It's part of Linux coreutils.

nl lines.txt
 1  $bkWTN
 2  $cV8$.