I have a file which contains following text
<MY_TEXT="XYZ" PATH="MNO" #First occurrence of MY_TEXT
<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> #Second occurrence of MY_TEXT
<MY_TEXT="ABC" PATH="EFG" #Third occurrence of MY_TEXT
<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> #Fourth occurrence of MY_TEXT
My task is to find a text in line which has <MY_TEXT="XYZ"
, it may have spaces in start and then find its closing \MY_TEXT
So output is kind of
<MY_TEXT="XYZ" PATH="MNO" #First occurrence of MY_TEXT
<location= "XYZ" path="ABC"
\location>
<R_DATA = MNOP
<Mylocation ="ghdf" stime=20150301 etime=20150401 > #First occurrence of Mylocation
<Mylocation ="ghdf" stime=20150401 etime=20150501 > #Second occurrence of Mylocation
\R_DATA>
<Blah>
\MY_TEXT>
Then it finds last occurrence of Mylocation i.e #Second occurrence of Mylocation
here and modified the text etime=20150501
to something
and append a new line after it inline in the file.
I came across this link Sed to extract text between two strings . But using sed command here either fetches me nothing when I use -n option or prints entire file when i remove -n . So I am not able to process the text further as I am not able to extract the text I want in the first place.
I also tried sed -n '/^ *START=A *$/,/^ *END *$/p' yourfile
. But of no use. Can you guys help me as my scripting is not great. Thanks in advance.