'''
# text.txt
1234121|abcd1|p|1234a
1234122|abcd2|c|1234b
1234123|abcd3|p|1234c
#target - split text.txt into 2 files
case
when the 3rd field is 'P' then pfile.txt
when the 3rd field is 'c' then cfile.txt
'''
# Python script
os.remove("pfile.txt")
os.remove("cfile.txt")
fo = open("text.txt","r")
for line in fo:
listline = line.strip(',').split('|')
if 'p' in listline[2:3]:
with open("pfile.txt","a+") as pf:
pf.write(line)
else:
with open("cfile.txt","a+") as cf:
cf.write(line)
fo.close()
pf.close()
cf.close()