hi experts, I have a new quesiton following what I asked before:
http://www.daniweb.com/software-development/python/threads/436159/python-remove-lines-when-two-specified-words-in-the-same-line
I am still new python user, and hope and get your help again.
my task is to do the following
Python Remove current and following 3 lines when two specified words in the same line
I have a test.txt like this:
BNBCD 1.00000000E+00 3.00000000E+00 0.00000000E+00 0.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
BEUSLO 2.00000000E+00 3.00000000E+00 0.00000000E+00 0.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
BEUSLO 3.00000000E+00 3.00000000E+00 0.00000000E+00 0.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
BNBCD 4.00000000E+00 3.00000000E+00 0.00000000E+00 0.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
hope the output file to be:
BNBCD 1.00000000E+00 3.00000000E+00 0.00000000E+00 0.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
BNBCD 4.00000000E+00 3.00000000E+00 0.00000000E+00 0.00000000E+00
1.00000000E+00 1.00000000E+00 0.00000000E+00 2.00000000E+00
is there any one can help? in the last discusstion, you helped and saying that
target = '4.00000000E+00'
remove_next = False
with open('test1.txt') as infile:
with open('output.txt', 'w') as outfile:
for line in infile:
if remove_next:
remove_next = False
print 'removed next:\t', line,
elif line.startswith('BNBCD') and target in line:
remove_next = True
print 'removed:\t', line,
else:
outfile.write(line)