AWK String replacement

I have an xml file with following tags
<NewTag>value123</xyz>
<NewTag>value321</abcd>

I have to replace the values in between the tags with some value ( VAL1/VAL2)
but the thing the ending tag can be any thing, for this i need a awk command

currently i am using this but it doesn't work:confused:

awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" "/<$TAGNAME(.+)>/&&n==++c{sub(\"<$TAGNAME>(.+)>\",s)}1" $FILENAME

the problem with this expression is the string s which i am building is a static one it doesn't take care of the changing ending tags!!

can some one suggest me the proper expression?:rolleyes:

I tried to understand it but I didn't. Can you post a sample output of what you want to have? And why can the ending Tag be another than the opening Tag?

what i exactly want to do is this

the xml file i need to change contains followin tags

<Myproperty Name="Colour">RED</Myproperty>
<MyName NickName="ppp">MYName</MyName>

you can see that the starting tag and ending tag are different!
i need to get the following out put when i execute the command

<Myproperty Name="Colour">GREEN</Myproperty>
<MyName NickName="ppp">URName</MyName>

hope it's clear?:stuck_out_tongue:

cat infile

<Myproperty Name="Colour">RED</Myproperty>
<MyName NickName="ppp">MYName</MyName>

sed -e '/"Colour"/ { s/>RED</>GREEN</g }' -e '/"ppp"/ { s/MYName/URName/g }' infile

<Myproperty Name="Colour">GREEN</Myproperty>
<MyName NickName="ppp">URName</MyName>

:b:Thanks a lot zaxxon!

can you tell me how can i replace only a speific occurance of this pattern! i mean say i want o replace the 3rd occurance of the RED, then what will be flag for the sed command instead of "g" ?

sed -e '/"Colour"/ { s/>RED</>GREEN</3 }' -e '/"ppp"/ { s/MYName/URName/3 }' infile

But remember that it will just be the 3rd of the line, not of the whole input as one.