I have several larger files (400-800MiB) in which I need to convert Hex values to others. I can do this in some Hex editor, but I would like to do it automatically, in a Bash script.
I know how to check with xxd whether a given value is in a file:
FILE='file.vpk'
SEARCH_STRING='MaxRagdollCount'
OLD_HEX_VALUE="$( echo -n "$SEARCH_STRING" | xxd -p )"
HEX_VALUE=($( xxd -p "$FILE" | grep -E -o "${OLD_HEX_VALUE}222022[0-9]{,2}22" ))
echo "$HEX_VALUE"
but I can't figure out how to edit it.
I need to replace the value of
MaxRagdollCount" "any_number"
(4d6178526167646f6c6c436f756e742220223222)
with
MaxRagdollCount" "9"
(4d6178526167646f6c6c436f756e742220223922).
Assuming the "any number" is always a single digit number (i.e. two hexadecimal characters) the following should work: