I need to read a file and replace a value in GB by a value in MB. The value is not always in GB and most of the time a decimal. The only way I found was the following:
for /F "tokens=1,2,3,4 delims=," %%A in (file.log) do (
echo.%%D|findstr "GB Available" >nul 2>&1
if errorlevel 0 if not errorlevel 1 (
set value=%%D
echo value:!value! REM looks like "Available= 12.53GB"
set value_short=!value:~11!
set value_short=!value_short: GB=! REM looks like "12.53"
echo value_short:!value_short!
set /a value_converted=!value_short:.=!*10
echo value_converted:!value_converted! MB REM looks like "1253 MB"
set "line=%%D"
set "line=!line: !value_short!=!value_converted!!"
echo LINE: !line! REM Need to have something like: "Available= 1253MB"
)
if errorlevel 1 (
echo no
)
)
Unfortunately set "line=!line: !value_short!=!value_converted!!"
doesn't work, I also tried with % instead of ! but it's not working. What is wrong with this line?
The main goal is to have values in MB in my file and for that I read the file and write the lines in MB without touching them in a new file, and re-write the lines with GB by converting them. If you have a simpler way, it's more than welcome!