need to break out a file into three separate files based on first field e.g.
file = ['aaa sfsfs sfsdfs sdfes'
aaa srgfr grg ht hrhr
aaa egero eriore erore',
hh dsrgr rger ergerl rr
hh oefsrf werf ewf wfre,
k efwgwe wfwer fwe fwetf,
ddd fsff rgferw grwr
ddd wfrewe gptrg rer
ddd eortwer writwer erwo,
m fwewi qoovsd sjrrs fe ,]
so go through file and lines where the first three consecutive lines have the same first field send those three lines to file1, lines where only two cosecutive lines have the same first fields send to file 2 and rest which is only 1 unique first field to file 3 - so lines aaa ... and ddd ....would be in file1 etc..etc..
any idea how to read thru a file and do this is very much appreciated - Thanks
file = ['aaa sfsfs sfsdfs sdfes'
aaa srgfr grg ht hrhr
aaa egero eriore erore',
hh dsrgr rger ergerl rr
hh oefsrf werf ewf wfre,
k efwgwe wfwer fwe fwetf,
ddd fsff rgferw grwr
ddd wfrewe gptrg rer
ddd eortwer writwer erwo,
m fwewi qoovsd sjrrs fe ,]
so go through file and lines where the first three consecutive lines have the same first field send those three lines to file1, lines where only two cosecutive lines have the same first fields send to file 2 and rest which is only 1 unique first field to file 3 - so lines aaa ... and ddd ....would be in file1 etc..etc..
any idea how to read thru a file and do this is very much appreciated - Thanks
Comment