Search Keys and Replace Values in XML
<p>I have an xml file which looks like below</p>

<pre><code>&lt;name&gt;abcdefg&lt;/name&gt;
&lt;value&gt;123456&lt;/value&gt;
</code></pre>

<p>I am trying to write a script using sed to search for the tag "abcdefg" and then <strong>replace the corresponding value</strong> "123456" but unfortunately I am not able to find a logic to achieve above.
 Need help!</p>

<p>Whenever you have tag->value pairs in your data it's a good idea to create a tag->value array in your code:</p>

<pre><code>$ awk -F'[&lt;&gt;]' '{tag=$2; v[tag]=$3} tag=="value" &amp;&amp; v["name"]=="abcdefg" {sub(/&gt;.*&lt;/,"&gt;blahblah&lt;")} 1' file
&lt;name&gt;abcdefg&lt;/name&gt;
&lt;value&gt;blahblah&lt;/value&gt;
</code></pre>

python xml shell replace sed