How to append line numbers in front of each line in a file?
cat. No kidding,
cat has the
-n option to number the output lines, starting at 1:
cat -n file.txt
This works well both on Linux and Mac. Use the shell redirection to keep the output in a new file (don’t override the original file with the redirection though).