0

In the File Test1.jmx I need to replace a string value to be false where the value = true or 0 or null. I need to do this for all occurrences of the string in the file.

before:
<boolProp name="ThreadGroup.scheduler">true</boolProp>
after:
<boolProp name="ThreadGroup.scheduler">false</boolProp>

Here's my erroneous code:

overrides_scheduler="BLAAA FOO MOO"
overRides=$(awk -v newValue="$overrides_scheduler" '$0 ~ /boolProp name="ThreadGroup.scheduler"/ {a=$0; sub(/<boolProp name="ThreadGroup.scheduler">[a-zA-Z0-9]/,"<boolProp name=\"ThreadGroup.scheduler\">"newValue,a); print a; next;}{}1' "Test1.jmx");
echo  "$overRides" > "Test1.jmx"

Test1.jmx:

<boolProp name="ThreadGroup.scheduler">true</boolProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<boolProp name="ThreadGroup.scheduler">true</boolProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<boolProp name="ThreadGroup.scheduler">true</boolProp>
<boolProp name="ThreadGroup.scheduler"></boolProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<boolProp name="ThreadGroup.scheduler">0</boolProp>
0

2 Answers 2

2

With GNU sed:

sed -r 's|(<boolProp name="ThreadGroup.scheduler">)(true\|0\|null)(</boolProp>)|\1false\3|' Test1.jmx

Output:

<boolProp name="ThreadGroup.scheduler">false</boolProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<boolProp name="ThreadGroup.scheduler"></boolProp>
<longProp name="ThreadGroup.end_time">1363247040000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
Sign up to request clarification or add additional context in comments.

2 Comments

thanks for this. It works really well. However, the null value was meant to represent no value at all rather than the word null. Would you know how I can adjust the statement so that false is replaces where there is no value?
@user1654528: Remove string null from my answer.
0

I managed to do the following:

echo '<boolProp name="ThreadGroup.scheduler">true</boolProp>' | awk -F'\">|</' '/ThreadedGroup.scheduler/ {sub(/true/,"false");print}'

Can also be used with cat or putting the filename at the end of the command.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.