I am walking through a folder/directory and reading all files, checking if there is a certain tag, then replacing a specific string multiple times only when it is in between two certain strings/tags. Here is an example of the text files:
START $YES
N1 000 001 002
N2 TAG#1 004 008
N3 This is an apple
N4 006 005 003
(( TAG#2 ))
N5 This is an apple
I would like a solution that can open the files, check if START $YES or START $NO, and replace the string This is an apple into There is no apple in between TAG#1 and TAG#2 only if START $YES is present. I would prefer the original file to be left unaffected (create a new file or create a backup using the fileinput library).
I cannot post my python code at the moment, but I will update this post when I am back at my work desk with the code that I have attempted.