I am trying to read a txt-file with many values of pairs in two colmns (X-Y values) and I wand them to be writen in another txt-file with 4 pairs X-Y at each row (8 values per row).
So, from that:
0,038043 0,74061
0,038045 0,73962
0,038047 0,73865
0,038048 0,73768
0,03805 0,73672
0,038052 0,73577
0,038053 0,73482
0,038055 0,73388
0,038057 0,73295
0,038058 0,73203
0,03806 0,73112
0,038062 0,73021
0,038064 0,72931
0,038065 0,72842
0,038067 0,72754
0,038069 0,72666
to that:
0,038043 0,74061 0,038045 0,73962 0,038047 0,73865 0,038048 0,73768
0,03805 0,73672 0,038052 0,73577 0,038053 0,73482 0,038055 0,73388
0,038057 0,73295 0,038058 0,73203 0,03806 0,73112 0,038062 0,73021
0,038064 0,72931 0,038065 0,72842 0,038067 0,72754 0,038069 0,72666
I tried:
import itertools
files = [1, 2 ,3 ,4, 5, 6, 7,
8, 9, 10, 11, 12, 13]
for k in files:
print 'k =',k
with open("deflag_G{k}.inp".format(k=k)) as f1:
with open("deflag_G_{k}.inp".format(k=k),"w") as f2:
f2.writelines(itertools.islice(f1, 4, None))
f2.close()
f1.close()
But I am not taking 4 pairs (8 values per line) in the new file. Any help is appreciated.