title: Replacing a value in xml file using awk or sed
body: <p>I'd like to replace the value of <code>"ThreadGroup.num_threads"</code> which is <code>2000</code> with another value i.e. <code>500</code>. My file name is <em>"test.xml"</em></p>
  
  <p>here is the xml file that i want to replace <code>2000</code> value with <code>500</code>:</p>
  
  <pre><code>&lt;ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="JWT-API Thread Group" enabled="true"&gt;
      &lt;stringProp name="ThreadGroup.on_sample_error"&gt;continue&lt;/stringProp&gt;
      &lt;elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"&gt;
      &lt;boolProp name="LoopController.continue_forever"&gt;false&lt;/boolProp&gt;
      &lt;stringProp name="LoopController.loops"&gt;1&lt;/stringProp&gt; &lt;/elementProp&gt;
      &lt;stringProp name="ThreadGroup.num_threads"&gt;2000&lt;/stringProp&gt;
      &lt;stringProp name="ThreadGroup.ramp_time"&gt;1&lt;/stringProp&gt;
      &lt;boolProp name="ThreadGroup.scheduler"&gt;false&lt;/boolProp&gt;
      &lt;stringProp name="ThreadGroup.duration"&gt;&lt;/stringProp&gt;
      &lt;stringProp name="ThreadGroup.delay"&gt;&lt;/stringProp&gt;
  &lt;/ThreadGroup&gt;
  </code></pre>
  
  <p>I have made a script that helps to replace the value but somehow i am hard-coding the values as well as hardcoded the path location. I need a way so that it recognizes the location itself just as i defined in awk command and replaces the value using parameter as defined <code>$Ratio</code> </p>
  
  <pre><code>#!/bin/bash
  Ratio="500"
  for file in Sample.jmx; do
          awk -F"[&lt;&gt;]" '/ThreadGroup.num_threads/{print $3}' $file &gt; output.json
          sed -i 's:&lt;stringProp name="ThreadGroup.num_threads"&gt;2000&lt;/stringProp&gt;:&lt;stringProp name="ThreadGroup.num_threads"&gt;500&lt;/stringProp&gt;:' $file
  done
  Output=$((`cat &lt; output.json`))
  echo $Output
  #UpScale = number_of_threads / 1000
  UpScale=$((`cat &lt; output.json` / $Ratio))
  echo $UpScale
  </code></pre>