import re
filename1=open('6548_log0_20200708_01.txt','r') #The source file
filename2=open('6548_log0_20200708_02.txt','a') #Empty file, use to save the result
s_number='' #the number will be covered
d_number='' #the number you want use to insert
s_numbers =[] #list use to save the all numbers of the line s_number in
d_numbers=[] #list use to save the all numbers of the line d_number in
#the sign of the number you want to cover IMPORT L03566
s_sign=input('Please input the sign of the number you want to cover:')
#the sign of the number you want to use to insert INSERT PC_PYMAC_PART_COST
d_sign=input('Please input the sign of the number you want to use to insert:')
#Read the contents of the sourse file
for line in filename1.readlines():
if d_sign in str(line):
#findout the all numbers of this line
d_numbers = re.findall(r"\d+\.?\d*",str(line))
#the final number of the list is target
d_number=str(d_numbers[-1])
if s_sign in str(line) and d_numbers:
#findout the all numbers of this line
s_numbers=re.findall(r"\d+\.?\d*",str(line))
#the final number of the list is target
s_number=str(s_numbers[-1])
#replace the number
tt=re.sub(s_number,d_number,line)
filename2.write(tt)
continue
else:
#insert the content into the filename2
filename2.write(line)