Thank you I ended up using:
Code:
g4 = open('workfile4', 'wb')
for line in open('workfile3').readlines():
if re.match(r'^[0-9]{6}', line):
studentid = re.match(r'^[0-9]{6}', line).group()
else:
print studentid, ",", line
class1 = studentid, ",", line
s4 = str(class1)
g4.write(s4)
g4.close()
To clean the file(s) up I used a lot of:
Code:
scriptutil.freplace('.', shellglobs=('workfile3',),regexl=((r'\\$',r'', None),))
scriptutil.freplace('.', shellglobs=('example',),regexl=((r'([A-Z])\,([A-Z])',r'\1\2', None),))
I'm not sure how efficient the scriptil function is, but I am only working with about one thousand lines of text.