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,


    <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"/>
  • You can use the python xml library
    – Ijaz Ahmad
    Jul 11 '16 at 10:01

Using XMLStarlet:

xml ed -P \
    -u '//argument[@name="protocol"]/@is-required' -v true \
    -u '//argument[@name="protocol"]/@default-value' -v tcp \
    -u '//argument[@name="port"]/@is-required' -v true \
    -u '//argument[@name="port"]/@default-value' -v 7223 \
    -u '//argument[@name="username"]/@is-required' -v true \
    -u '//argument[@name="username"]/@default-value' -v admin \

Result for your sample:

    <argument name="protocol" is-required="true" default-value="tcp"/>
    <argument name="port" is-required="true" default-value="7223"/>
    <argument name="username" is-required="true" default-value="admin"/>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.