bash - Adding an element in a XML file without grammatic error -
i have xml file below
<rows> <row> <name>peter</name> <id>345</id> </row> <row> <name>matt</name> <id>567</id> </row> </rows> have achieved adding sub element file below: <rows> <row> <name>peter</name> <id>345</id> </row> <row> <name>matt</name> <id>567</id> </row> <row> <name>mano</name> <id>897</id> </row> </rows> problem added element not in sync rest of elements. im expecting same grammar(alignment) rest
code tried:
element="\t<row>\n\t <name>newname</name>\n\t <id>newid</id>\n\t</row>" c=$(echo $element | sed 's/\//\\\//g') echo "after c" sed "/<\/rows>/ s/.*/${c}\n&/" filename please assist.
probably straightforward answer insert records without indentation , use xmllint --format clean things after fact. proposed solution can provide error checking may useful you.
Comments
Post a Comment