I am trying to write a script that does certain operation on below text present in a file say myfile.txt
<MY_TEXT="XYZ" PATH="MNO"
<location= "XYZ" path="ABC"
\location>
<R_DATA = MNOP
<Mylocation ="ghdf" stime=20150301 etime=20150401 >
<Mylocation ="ghdf" stime=20150401 etime=20150501 >
\R_DATA>
<Blah>
\MY_TEXT>
<MY_TEXT="ABC" PATH="EFG"
<location= "QQQ" path="LLL"
\location>
<R_DATA = MNOP
<Mylocation ="ghdf" stime=20150301 etime=20150401 >
<Mylocation ="ghdf" stime=20150401 etime=20150501 >
\R_DATA>
<Blah>
\MY_TEXT>
Here i see that I have a line <MY_TEXT="XYZ" and then on this match i try and change the lines that lies between <MY_TEXT \MY_TEXT> . I need to make changes to line <Mylocation line and modify etime=20150401 to say and then append a new line after it. Now all this needs to be done in a file that i have passed or create a new file with above modification. I am looking for a way to this and its getting complicated by reading individual lines and keeping track of line.