been working in this batch code for a couple of days and I cannot make it work right. To give you a perspective, this code is intended to read a file that contains some "selected" numbers which refer to other files contained in another folder. These files contain a lot of data arranged by rows and columns. The first rows are not important so the code is skipping 50 rows to save time, then I am interested in the 2nd and 7th columns so these are exported to variables (A,B) for each row. If there is a combination of values between these two variables (e.g. A>1000 & B>0.03) on the same row the code is supposed to export the file number where this happened. Problem: the IFs that compare these columns don't work as expected, the GTR/GEQ don't seem to respect the "more than" and the code exports file numbers even when there is no such combination in the file. I have tried two codes so far:
Code 1
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=*" %%s in (selected.txt) do (
cd %~dp0\Melts\MeltNPTdis-8-%%s
for /f "skip=50 tokens=2,7 delims= " %%A in (file.txt) do (
if %%A GTR 1000 if %%B GTR 0.03 (
cd %~dp0
>>dummy.txt echo %%s
)))
Code 2, with check variables
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=*" %%s in (selected.txt) do (
cd %~dp0\Melts\MeltNPTdis-8-%%s
for /f "skip=50 tokens=2,7 delims= " %%A in (file.txt) do (
set /a x=0
set /a y=0
if %%A GTR 999 (
set /a x=1
)
if %%B GTR 0.03 (
set /a y=1
)
set /a z= !x! + !y!
if !z! EQU 2 (
cd %~dp0
>>dummy.txt echo %%s
)))
Can someone light me up on this one? I have isolated the problem to the IFs and have tried to define the variables differently like %%A or %%A%% not solving the issue. Thanks a lot!
0.03is treated as string and therefore compared with string rules