简体   繁体   English

如何通过使用Shell脚本sed命令替换文件中xml标记之间的值?

[英]How do I replace value between xml tag in a file by using shell scripting sed command?

I have a configuration file. 我有一个配置文件。 Ex: config.xml It has following configurations. 例如:config.xml它具有以下配置。

    <!-- 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. 我需要通过运行Shell脚本来更改值“ adminusername”和“ adminpassword”。 How can I achieve this using sed? 如何使用sed实现此目的?

Sed is not the right tool for the job. Sed不是适合该工作的工具。 Use an XML-aware tool that can really parse the XML. 使用可以真正解析XML的XML感知工具。

For example, in xsh I happen to maintain, you can write 例如,在xsh中,我碰巧要维护,您可以编写

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.) (假设XML的根元素称为Root ,提到的元素是其子元素,并且不再重复。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM