Hi All,
I have awk script for replacing the nth ocurance of a string in an xml file...
My code is like this
FILETYPE=xml
TAGNAME=type
OCCURANCE=$1
TAGVALUE=valueur
echo OCCURANCE:$OCCURANCE
echo TAGNAME:$TAGNAME
echo TAGVALUE:$TAGVALUE
awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" '/< type(.+)type>/&&n==++c{sub("<type>(.+)</type>",s)}1' application.xml
this is working correctly .. but if ia m replacing the <type tag with $TAGNAME inside singlequotes, its not working...
awk -v n=$OCCURANCE -v s="<$TAGNAME>$TAGVALUE</$TAGNAME>" '/<$TAGNAME(.+)$TAGNAME>/&&n==++c{sub("<$TAGNAME>(.+)</$TAGNAME>",s)}1' application.xml
How do we use a variable in the awk command?
Thanks in advance