Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active March 9, 2019 16:09
Show Gist options
  • Save xbalaji/b47b86fdb927b7142ea5c19f7fcf8bed to your computer and use it in GitHub Desktop.
Save xbalaji/b47b86fdb927b7142ea5c19f7fcf8bed to your computer and use it in GitHub Desktop.
add line number to a file
#! /usr/bin/env python
import sys
ifile = open(sys.argv[1], 'r')
ofile = open(sys.argv[2], 'w')
for c, line in enumerate(ifile, 1):
ofile.write("{} {}".format(c,line))
ifile.close()
ofile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment