使用 Shell 脚本根据条件编辑和更新 XML [英] Editing and Updating XML based on condition using Shell Script

查看:37
本文介绍了使用 Shell 脚本根据条件编辑和更新 XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Shell 脚本更改一个值(即 value="false").我怎么可能去做那件事.请给我任何建议.

I want to change a value (i.e., value="false") using Shell Script. How could I go about doing that. Please provide me with any suggestion.

我尝试过/使用过的:

我使用命令-> sed 's/true/false/g' ml.xml.

问题:

但所有 true 内容都改变了.

But all true content changed.

我想要什么:

我的要求是只更改某个特定的内容,而不是每个内容.

My requirement entails that only a certain specific content to be changed, not every content.

之前:property name="s" value="true"

之后:property name="s" value="false"

<bean id="a"
    class="com.s.analyzer.Analyzer" scope="singleton">
    <!--  *** CHANGE to true for first daily run, otherwise false *** -->
    <property name="s" value="true" />

    <property name="a1l" value="2.5" />
    <property name="mi" value="2000" />
    <property name="ma" value="1" />
</bean>

推荐答案

这是一个完全匹配(

This is an exact match (of <property name="s" value="true):

sed  -e "s/\(<property name=\"s\" value=\"\)true/\1false/g"  file

就地更改文件:

sed  -i "s/\(<property name=\"s\" value=\"\)true/\1false/g"  file

如果您想要 的精确匹配,则:

If you want an exact match of <property name="s" value="true" />, then:

sed  -e "s/\(<property name=\"s\" value=\"\)true\(\" \/>\)/\1false\2/g"  file

这篇关于使用 Shell 脚本根据条件编辑和更新 XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆