Skip to content

Instantly share code, notes, and snippets.

@laserson
Created May 18, 2010 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laserson/405146 to your computer and use it in GitHub Desktop.
Save laserson/405146 to your computer and use it in GitHub Desktop.
import sys
import re
rev_gr_re = re.compile(r'([0-9]+)>{1}')
correct = lambda s: rev_gr_re.sub(r'>\1',s) + '\n'
if len(sys.argv) == 3:
ip = open(sys.argv[1],'r')
op = open(sys.argv[2],'w')
else:
raise Exception, "Must supply an input and output file."
for line in ip:
if line.startswith('FT ') and len(line[:20].split()) == 2:
line = line.rstrip()
corrected_lines = [line]
while line[-1] == ',':
line = ip.next().rstrip()
corrected_lines += [line]
corrected_lines = map(correct,corrected_lines)
op.write(''.join(corrected_lines)) # newlines are added in "correct" lambda fn
else:
op.write(line)
ip.close()
op.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment