in reply to Remove line and modify another

Based upon your question, I don't know how to help you.

Please do the work to post a simple code example that demonstrates your problem.
I don't need your whole program, just the problematic parts.

Update: you say: My current script is very long and consists of general substitutes. but you apparently cannot do some relatively simple stuff. Show some code.