I am trying to write a bash script or something similar, that I can use to modify all occurrences in a bunch of xml files with one click. I have 24 xml files, each containing a few dozen lines and with the attribute Torque="SOMENUMBER"
inside them about 3-5 times each. I would LIKE to replace those with 1.25 times their value to simply add 25% torque to every motor in this game.
(Doing it this way would be useful, since mods and game patches will overwrite these and I can quickly experiment with other values.)
I came up with the idea to use sed -n -e 's/Torque="\(.*\)"/\1/p' <filename.xml
to extract the number, put it in a variable and then I would have no idea how to get it back in there at the right place and also the sed
command above outputs all occurrences of Torque at once.
xmlstarlet could probably do it from what I have googled, but it always complains about the xml files containing more than one root element. Maybe I should somehow add a temporary tag <root_temp><\root_temp>
around everything somehow, let xmlstarlet run its magic, remove the tags again and save the file? It's been years, since I dabbled with bash scripts, I would also be willing to do it with python, cpp, learn the basics of a new language, I don't care xD
Sample XML:
<_templates>
<Engine>
<RUScoutModernEngine BrakesDelay="0.5" />
</Engine>
</_templates>
<EngineVariants>
<Engine
_template="RUScoutModernEngine"
CriticalDamageThreshold="0.7"
DamageCapacity="120"
DamagedConsumptionModifier="1.2"
EngineResponsiveness="0.35"
FuelConsumption="1.5"
Name="ru_scout_modern_engine_0"
Torque="70000"
DamagedMinTorqueMultiplier="1.0"
DamagedMaxTorqueMultiplier="0.6"
MaxDeltaAngVel="0.01"
>
<GameData
Price="1900"
UnlockByExploration="false"
UnlockByRank="1"
>
<UiDesc
PLACE="HOLDER"
/>
</GameData>
</Engine>
<Engine
BLA="BLA"
Torque="80000"
BLA="BLA"
>
<GameData
Price="5500"
UnlockByExploration="true"
UnlockByRank="1"
>
<UiDesc
PLACE="HOLDER"
/>
</GameData>
</Engine>
<Engine
BLA="BLA"
Torque="76000"
BLA="BLA"
>
<GameData
BLA="BLA"
>
<UiDesc/>
</GameData>
</Engine>
</EngineVariants>