I have an XML file like below. I want change the values at is-required place and default-value place of each argument name using a shell script.. where argument name=protocol then is-required = true and default-value=tcp,where argument name =port then is-required = true default-value= 7223,where argument name =then and is-required = true default-value=test,Example:<task-arguments>    <argument name=protocol is-required=false default-value=ssl/>    <argument name=port is-required=true default-value=7222/>    <argument name=username is-required=true default-value=admin/></task-arguments>
How to change values in XML file
xml
In general, XML processing should be done with an XML parser.UPDATE: In fact, I think it's unfortunate that this answer was picked as the accepted answer since @SatoKatsura's answer is in all ways correct and better. It uses a proper XML parser and it is shorter. See also comments from @cas to my answer.  XML parsing really should not be attempted with line-oriented tools.However, treating you document as plain text:#!/usr/bin/sed -f/argument name=protocol/{    i\<argument name=protocol is-required=true default-value=tcp/>    d}/argument name=port/{    i\<argument name=port is-required=true default-value=7223/>    d}/argument name=username/{    i\<argument name=username is-required=true default-value=test/>    d}This sed script will find the lines that you want to modify and replace the whole line with a line containing the XML that you want.I'm choosing to do it in this (rather heavy-handed) way, because it gives you an easy way to change the values to whatever you want, and does not rely on too much regular expression wizardry.EDIT:The script would go in a file of its own, maybe script.sed.  You would then run it with$ sed -f script.sed data.xml >data.newThis will apply the script to the file data.xml and output the result into the file data.new.The following is a script that allows you to set the values of the protocol, port and user, as well as what data files should be read and written:#!/bin/shxmlfile_in=data.xmlxmlfile_out=data.newprotocol=tcpport=7223user=testsed -f /dev/stdin $xmlfile_in >$xmlfile_out <<END_SED/argument name=protocol/{    i\\<argument name=protocol is-required=true default-value=$protocol/>    d}/argument name=port/{    i\\<argument name=port is-required=true default-value=$port/>    d}/argument name=username/{    i\\<argument name=username is-required=true default-value=$user/>    d}END_SED