linux - Shell script help on finding and replacing strings -


i have config file hive-site.xml

one configuration element is;

  <property>     <name>hadoop.embedded.local.mode</name>     <value>true</value>   </property> 

i want change "true" "false" shell script. in file there lots of configuration elements such as;

   <value>true</value>  

tags.

so "sed" command used find , replace strings difficult used here knowledge. appreciate if can me this.

this job xpath , reasonable xml library. doing shell script directly going create complicated , fragile solution. i'm going use python , popular lxml library example:

from lxml import etree  tree = etree.fromstring('''   <property>     <name>hadoop.embedded.local.mode</name>     <value>true</value>   </property> ''')  e = tree.xpath('//property[name="hadoop.embedded.local.mode"]/value')[0] e.text = 'false' print etree.tostring(tree) 

basically selects property node (anywhere in doc) if contains <name> element value, selects value element. can modify element's content liking , print string again. xpath standard, same code ought work in other implementations well.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -