And I wanted to update depends this xml as (in side the tag <subtag name="y"/>) depending upon the conditions like if 1,I have to update the first tag with the above mentioned tag and second and so on..
I have a string like x,y,z and xml file contains
<tag name="x" version="1.0">
</tag>
<tag name="y" version="1.0">
</tag>
<tag name="z" version="1.0">
</tag>
If I pass x then 'x' application getting updated as
<tag name="x" version="1.0">
<sometext/>
</tag>
If I pass y then 'y' application getting updated as
<tag name="y" version="1.0">
<sometext/>
</tag>
If I pass z then 'z' application getting updated as
<tag name="z" version="1.0">
<sometext/>
</tag>
---------- Post updated at 12:34 PM ---------- Previous update was at 12:32 PM ----------
For that I am searching every end tag then navigate to start tag then I will use sed to update the particular tag.
#!/bin/ksh
touch optFile # create empty output file
echo "Enter tag name:\c" # ask input tag name. E.g. "x" or "y"
read tag # read input
cat xmlFile | while read line # read each line of xmlfile
do
if [ "$line" = ".*\<tag name\=\"$tag\".*" ] ; then # if line contains matching tag then
echo "$line" >> optFile # write original line in output file
echo "\<sometext\/\>" >> optFile # append extra line after matching tag line in output file
else # else
echo "$line" >> optFile # write line as it is in output file
fi
done
---------- Post updated at 01:16 PM ---------- Previous update was at 01:04 PM ----------
cat xmlFile | while read line # read each line of xmlfile
do
if [ "$line" = ".\<tag name\=\"$tag\"." ] ; then # if line contains matching tag then
echo "$line" >> optFile # I need to get </tag> so that I can use this command==> sed '/<\/tag>/i\ <sometext\/\> ' $file $file2
echo "\<sometext\/\>" >> optFile # append extra line after matching tag line in output file
else # else
echo "$line" >> optFile # write line as it is in output file
fi
done