I'd like to replace the value of "ThreadGroup.num_threads"
which is 2000
with another value i.e. 500
. My file name is "test.xml"
here is the xml file that i want to replace 2000
value with 500
:
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="JWT-API Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">1</stringProp> </elementProp>
<stringProp name="ThreadGroup.num_threads">2000</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration"></stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
</ThreadGroup>
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 $Ratio
#!/bin/bash
Ratio="500"
for file in Sample.jmx; do
awk -F"[<>]" '/ThreadGroup.num_threads/{print $3}' $file > output.json
sed -i 's:<stringProp name="ThreadGroup.num_threads">2000</stringProp>:<stringProp name="ThreadGroup.num_threads">500</stringProp>:' $file
done
Output=$((`cat < output.json`))
echo $Output
#UpScale = number_of_threads / 1000
UpScale=$((`cat < output.json` / $Ratio))
echo $UpScale