I have the following XML:
<xml>
    <bean id="bean1"
         class="class1"
         singleton="false">
        <property name="dbPoolName" value="pool"/>
        <property name="dirName" value="myDir"/>
        <!--              <property name="MyProperty" value="5000"/> -->
    </bean>
    <bean id="bean2"
         class="class2"
         singleton="false">
        <property name="dbPoolName" value="pool"/>
        <property name="dirName" value="myDir"/>
        <!--              <property name="MyProperty" value="5000"/> -->
    </bean>
    <bean id="bean3"
         class="class3"
         singleton="false">
        <property name="dbPoolName" value="pool"/>
        <property name="dirName" value="myDir"/>
        <!--              <property name="MyProperty" value="5000"/> -->
    </bean>
</xml>
I need to uncomment the element:
<!--              <property name="MyProperty" value="5000"/> -->
Only inside bean with id "bean3". Then I need to modify its value, so that it is 50 instead of 5000.
I have tried using the following command:
grep -A 4 "bean3" file.xml | sed 's/<!--//' | sed 's/-->//' | sed 's/5000/50/'
But I am not able to replace it in file.
Should I use sed and/or grep?
grepwill extract only lines matching a pattern. The rest are removed. In this case, you want to keep all the other lines too. But the restriction that you only want to modify thebeantags withid="bean3"complicates things. I would suggest using something that actually parses XML, but it might not pick up the comments.