Reputation: 485
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?
Upvotes: 1
Views: 435
Reputation: 241828
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.)
Upvotes: 1