I am trying to set a variable using if else statements. The problem is that the else if "%%D"GEQ "%%G" (set var=%%G)
is not executing consistently. I am not sure what is wrong.
Here is my code:
@echo on
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=1-8* delims=," %%A IN (results.csv) DO (
if "%%D" equ 0 (
set var=0
) else if "%%D" GEQ "%%G" (
set var=%%G
) else (set var=%%D)
set "y=%%A,%%B,%%C,%%D,%%E,%%F,%%G,%%H,!var!"
echo !y!>>final.csv
)
Here is a sample of my input file.
"01185901095","11","0379-0005","50","001","0","3","3"
"01185901215","11","0379-0013","138","001","0","4","2"
Here is the output I get in final.csv
"01185901095","11","0379-0005","50","001","0","3","3","3"
"01185901215","11","0379-0013","138","001","0","4","2","138"
My expected output is:
"01185901095","11","0379-0005","50","001","0","3","3","3"
"01185901215","11","0379-0013","138","001","0","4","2","4"
Line 2 in the output is the problem . %%D is greater than %%G so I expect the value of %%G (or 138 is greater than 4 so I expect 4)