参见英文答案 >
Replace dynamic content in XML file 3个
我想将我的xml“abc.xml”元素的值更改为存储在变量$value中的值,即
我想将我的xml“abc.xml”元素的值更改为存储在变量$value中的值,即
$value =’abc’;
<annotation> <filename>img_000001016592.png</filename> <folder>Rec_20121219_171905</folder> <source> <sourceImage>The MIT-CSAIL database of objects and scenes</sourceImage> <sourceAnnotation>LabelMe Webtool</sourceAnnotation> </source> <imagesize> <nrows>481</nrows> <ncols>640</ncols> </imagesize> </annotation>
解决方法
也许你的意思是使用sed.
value='abc' sed -i "s|abc.txt|$value|g" abc.xml
您必须在shell中运行它,或者作为带有标题#!/ bin / sh的shell脚本运行.
—-更新—-
#!/bin/sh value="something" sed -i "s|\(<filename>\)[^<>]*\(</filename>\)|\1${value}\2|" abc.xml
如果需要在一行中替换多个实例,请将g添加到sed命令.
sed -i "s|\(<filename>\)[^<>]*\(</filename>\)|\1${value}\2|g" abc.xml
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。