Strange Issue with FOR LOOP; ignoring last record?
Posted: 17 Jul 2019 04:00
HI Folks -
I have the following script created to output unique values from a list. Prior to this step, I sort a single columntext file extracted from a data-dump from one of my data bases. From here, I need to pull out any unique records.
The issue is when the uniq record is the LAST record, for some reason it doesn't pull it out. Here is my ssyntax:
Here is my file, notice the last record is unque but it's not pulling it out. Anyone know why?
I have the following script created to output unique values from a list. Prior to this step, I sort a single columntext file extracted from a data-dump from one of my data bases. From here, I need to pull out any unique records.
The issue is when the uniq record is the LAST record, for some reason it doesn't pull it out. Here is my ssyntax:
Code: Select all
rem Output unique values
SET "LAST="
SET "COUNT=0"
(FOR /F "usebackq delims=" %%A IN ("out2.txt") DO (
IF "%%A" equ "!LAST!" (
SET /A "COUNT+=1"
) ELSE (
IF "!COUNT!" equ "1" ECHO Non_Combo_Firms,!LAST!
SET COUNT=1
)
SET "LAST=%%A"
)) > "%NCF_LF%"
Code: Select all
C-12528168
C-12528168
C-12528170
C-12528170
C-12528174
C-12528174
C-12528180