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.

linux / unix command: xmllint


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -