Skip to content

Instantly share code, notes, and snippets.

@tkh44
Created November 22, 2011 21:57
Show Gist options
  • Save tkh44/1387146 to your computer and use it in GitHub Desktop.
Save tkh44/1387146 to your computer and use it in GitHub Desktop.
Surgery Benefit Formatter
import fileinput
import sys
import re
filename = sys.argv[1]
def benefitFormat(matchobj):
print matchobj.group(0)
return '[benefit name=\"' + matchobj.group(0).rstrip() + '\"'
with open(filename) as infile:
with open(filename.replace('.txt', '')+"_formatted.txt", "w") as outfile:
for i, line in enumerate(infile):
print "Line %s: " % i
#print line
outfile.writelines(re.sub('([A-Za-z]+[A-Za-z/,\s18]+\s)+', benefitFormat, line, count=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment