I have a test.txt like this:
GCOORD 5.98400000E+03 1.19901791E+01 8.29785919E+00 -1.10000002E+00
GCOORD 5.98500000E+03 1.25401793E+01 8.84785938E+00 -6.59999990E+00
GCOORD 5.98600000E+03 1.30901794E+01 9.39785957E+00 -1.21000004E+01
BNBCD 3.66000000E+02 6.00000000E+00 4.00000000E+00 4.00000000E+00
4.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
BNBCD 4.17000000E+02 6.00000000E+00 1.00000000E+00 1.00000000E+00
1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
BNBCD 5.16000000E+02 6.00000000E+00 1.00000000E+00 1.00000000E+00
1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
BNBCD 5.58000000E+02 6.00000000E+00 4.00000000E+00 4.00000000E+00
4.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
BNBCD 5.90000000E+02 6.00000000E+00 4.00000000E+00 4.00000000E+00
4.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
BNBCD 6.08000000E+02 6.00000000E+00 4.00000000E+00 4.00000000E+00
4.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
That i want to do is remove the line and the line after this line (if line start with 'BNBCD' and this line contains '4.00000000E+00')
the result will be:
GCOORD 5.98400000E+03 1.19901791E+01 8.29785919E+00 -1.10000002E+00
GCOORD 5.98500000E+03 1.25401793E+01 8.84785938E+00 -6.59999990E+00
GCOORD 5.98600000E+03 1.30901794E+01 9.39785957E+00 -1.21000004E+01
BNBCD 4.17000000E+02 6.00000000E+00 1.00000000E+00 1.00000000E+00
1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
BNBCD 5.16000000E+02 6.00000000E+00 1.00000000E+00 1.00000000E+00
1.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
I am writing a script to run, but some errors, can someone help and tell how to make it run?
my code:
f = open("test.txt","r")
_file = open("file_08.txt", "w")
lines=f.readlines()
f.close()
count=-1
for line in lines:
count=count+1
if not line.strip():
continue
else:
clean_line = line.strip().split()
if clean_line[0]== 'BNBCD':
for i in range(len(clean_line)):
if clean_line[2] == '4.00000000E+00':
p=1
continue
print p
if p==1:
#for i in range(len(clean_line)):
if clean_line[0] == '4.00000000E+00':
p=0
continue
else:
_file.writelines(line)
_file.close()