用于更改xml元素的shell脚本[复制]
发布时间:2020-12-16 23:17:29 所属栏目:百科 来源:网络整理
导读:参见英文答案 Replace dynamic content in XML file????????????????????????????????????3个 我想将我的xml“abc.xml”元素的值更改为存储在变量$value中的值,即 $value =’abc’; annotation filenameimg_000001016592.png/filename folderRec_20121219_17
参见英文答案 >
Replace dynamic content in XML file????????????????????????????????????3个
我想将我的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> 需要shell脚本,它有一个变量,它包含变量中的值,然后将abc.xml的元素文件名的值更改为变量中的值. 解决方法
也许你的意思是使用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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |