Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nepsilon/c090402514f3bc65093265a7a579042d to your computer and use it in GitHub Desktop.
Save nepsilon/c090402514f3bc65093265a7a579042d to your computer and use it in GitHub Desktop.
How to append line numbers in front of each line in a file? — First published in fullweb.io issue #86

How to append line numbers in front of each line in a file?

Just use 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment