I was wondering if someone could help me with how to copy an xml tag and its value to another xml file under same root tag. Create the root tag if it doesn't exist.Here is an input output example.INPUT: string.xml<resource>    <string name=app_name>MyExampleApp</string>    <string name=profile>My Profile</string>    <string name=messages>My Messages</string></resource>$ command profile string.xml string1.xmlOUTPUT: string1.xml<resource>    <string name=profile>My Profile</string></resource>I was looking for that Command and options. Not necessarily in that order. Please help me out here. Any Linux/Unix/Mac command will do
How to copy an xml tag and its value into another xml file under the same root tag
text processing;xml
Using XMLStarlet, you could delete all the string nodes under the root node whose name attribute is not profile:$ xml ed -d '/resource/string[@name != profile]' string.xml<?xml version=1.0?><resource>  <string name=profile>My Profile</string></resource>Add -O after ed if you don't want the XML declaration line.