Created
May 18, 2010 15:50
-
-
Save laserson/405146 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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