Home > Software design >  replace tag content in xml file using sed command
replace tag content in xml file using sed command

Time:02-03

I want to replace the "value" tag after the "name" tag with false using sed command. I've tried multiple things without success. There is a lot of "value" tags in my file so i think that i should use this tag <name>hive.metastore.schema.verification</name> in regex`

<property>
    <name>hive.metastore.schema.verification</name>
    <value>true</value>
    <description>
    foobar 
    </description>
</property>

This is my command :

sed '/<property>/!b;:a;/<\/property>/!{$!{N;ba}};/hive.metastore.schema.verification</s/.*\n/&<value>false<\/value>\n/' hive-site.xml

CodePudding user response:

With the good tool, using :

xmlstarlet edit -L \
    -u '/property[./name/text() = "hive.metastore.schema.verification"]/value' \
    -v false file.xml

Don't use sed nor regex to parse XML

  • Related