Created
September 10, 2014 06:44
-
-
Save bindiego/66582cbdd52e23c04b6d to your computer and use it in GitHub Desktop.
plain text processing
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 csv | |
import re | |
filein = open('lcshtopics-synonymlinkage.tsv', 'r') | |
#filein = open('abc.tsv', 'r') | |
fileout = open('out', 'w') | |
try: | |
i = 1 | |
for line in filein: | |
if (i == 1): | |
i = i + 1 | |
continue | |
j = 1 | |
newline = '' | |
for token in re.split(r'\t+', line): | |
if (j == 2 or j == 3): | |
j = j + 1 | |
continue | |
elif (j == 1): | |
newline = token | |
#print 'line %d: %s' % (i, token) | |
j = j + 1 | |
elif(j == 4): | |
newline = newline + '+++++' + token | |
fileout.write(newline) | |
#print newline | |
i = i + 1 | |
finally: | |
filein.close() | |
fileout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment