1

I have a configuration file. Ex: config.xml It has following configurations.

    <!-- Admin username for the Authentication manager. -->
    <Username>adminusername</Username>
    <!-- Admin password for the Authentication manager. -->
    <Password>adminpassword}</Password>

I need to change the value "adminusername" and "adminpassword" by running a shell script. How can I achieve this using sed?

1

1 Answer 1

1

Sed is not the right tool for the job. Use an XML-aware tool that can really parse the XML.

For example, in xsh I happen to maintain, you can write

open config.xml ;
set /Root/Username "newname" ;
set /Root/Password "newpassword" ;
save :b ;

(Provided the XML's root element is called Root, the mentioned elements are its children, and they aren't repeated.)

Sign up to request clarification or add additional context in comments.

1 Comment

I hadn't come across xsh. Another similar tool is xmlsh - www.xmlsh.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.