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?

Mad
  • 435
  • 2
  • 17
  • sed is not a good choice to work on xml input, see https://stackoverflow.com/questions/1794995/find-and-replace-in-xml-file-using-sed – Sundeep Feb 17 '17 at 10:56

1 Answers1

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.)

choroba
  • 231,213
  • 25
  • 204
  • 289