I would like to replace sequence of numbers in file with some other sequence number. for example I want the code find :
5723
5724
5725
.
.
in the file and replace it with
1
2
3
.
.
the format of file is like this :
5723 1 4 0.0530 40.8469574826 23.6497161096 71.2721134368 # hc
5724 1 4 0.0530 41.2184192051 22.0657965663 70.7655969235 # hc
5725 1 4 0.0530 40.1209834536 22.2320441560 72.1100610464 # hc
5726 1 2 0.0390 38.2072673529 21.5636299564 70.4226801302 # ni
5727 1 3 0.0080 39.1491515464 22.7414447024 70.1836001683 # c1
5728 1 4 0.0530 38.6092690356 23.6286807105 70.4379331882 # hc
5729 1 5 -0.1060 39.4744610200 22.9631667398 68.7099315672 # c
5730 1 4 0.0530 39.7733681662 22.0164196098 68.2561710623 # hc
5731 1 4 0.0530 40.3997078786 23.5957910115 68.6602988667 # hc
5732 1 6 -0.1768 37.4127695738 20.7445960448 69.5033013922 # c5
5733 1 7 0.1268 37.5907142 20.8480311755 68.4090824525 # h
I've written this cod to do this but it just replace the first , how can I correct this code ?
import os
import sys
import fileinput
masir = os.curdir + '\\test\\'
input = open('poly-IL9.data', 'r')
output = open('out.data', 'w')
range1 = range(5722,13193)
range2 = range(1,7472)
for i in range(len(x1)):
for j in range(len(y1)):
x = str(range1[i])
y = str(range2[j])
clean = input.read().replace(x,y)
output.write(clean)