Reputation: 325
do ( ) wasn't working for the code I got online so instead I'm using do :processline. The problem is "continue;" doesn't work when wanting to go to the next iteration. The problem with this is it's executing :eof for each iteration rather than post loop...how to avoid this? Thanks
SET NGCSV=UserList3Col.csv
SET NGCSVT1=UserList3Col.csv.temp1
SET NGCSVT2=UserList3Col.csv.temp2
SET NGFINAL=UserListFinal.csv
del %NGFINAL%
set /a c=0
for /f "tokens=1" %%i in (groupList.txt) do call :processline %%i
goto :eof
:processline
SET GROUP=%*
setlocal EnableDelayedExpansion
net group /domain "GG-%GROUP%" > %NGCSV%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM Now strip out the crap
REM ...make a temporary copy
COPY %NGCSV% %NGCSVT2%
REM ...strip off the crap using alternating temp files
findstr /B /L /V /C:"The request" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Group name" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"Comment" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Members" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"-----" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"The command" %NGCSVT1% > %NGCSVT2%
REM ...make the last temporary copy the final copy and clean up
COPY %NGCSVT2% %NGCSV%
DEL %NGCSVT1%
DEL %NGCSVT2%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM ...Column 1
for /F "tokens=1" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 2
for /F "tokens=2" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 3
for /F "tokens=3" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
del %NGCSV%
continue; rem Doesn't work
:eof
set /a c=c+1
echo %c%
Upvotes: 2
Views: 18702
Reputation: 1925
I use this one to continue the loop (note :next
label MUST have some code, I use echo smth > nul
):
for /f "eol= tokens=*" %%a in (settings.ini) do (
set line=%%a
if "%line%"=="!line:[Server]=!" (
echo ***[Server] section found
goto :next
)
:next
echo continue this loop > nul
)
Upvotes: 2
Reputation: 41234
continue;
is not an internal or external command.
EOF
is an internal label in CMD and doesn't need to be included.
Test this:
SET NGCSV=UserList3Col.csv
SET NGCSVT1=UserList3Col.csv.temp1
SET NGCSVT2=UserList3Col.csv.temp2
SET NGFINAL=UserListFinal.csv
del %NGFINAL%
set /a c=0
for /f "tokens=1" %%i in (groupList.txt) do call :processline %%i
goto :continue
:processline
set /a c=c+1
echo %c%
SET GROUP=%*
setlocal EnableDelayedExpansion
net group /domain "GG-%GROUP%" > %NGCSV%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM Now strip out the crap
REM ...make a temporary copy
COPY %NGCSV% %NGCSVT2%
REM ...strip off the crap using alternating temp files
findstr /B /L /V /C:"The request" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Group name" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"Comment" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"Members" %NGCSVT1% > %NGCSVT2%
findstr /B /L /V /C:"-----" %NGCSVT2% > %NGCSVT1%
findstr /B /L /V /C:"The command" %NGCSVT1% > %NGCSVT2%
REM ...make the last temporary copy the final copy and clean up
COPY %NGCSVT2% %NGCSV%
DEL %NGCSVT1%
DEL %NGCSVT2%
REM * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
REM ...Column 1
for /F "tokens=1" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 2
for /F "tokens=2" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
REM ...Column 3
for /F "tokens=3" %%A in (%NGCSV%) do @echo %GROUP%,%%A >> %NGFINAL%
del %NGCSV%
goto :EOF
:continue
echo this is reached after the entire file is parsed
pause
This code should work in the same way too with the exception that !
characters become a poison character when delayed expansion is used.
@echo off
setlocal enabledelayedexpansion
SET NGCSV=UserList3Col.csv
SET NGCSVT1=UserList3Col.csv.temp1
SET NGCSVT2=UserList3Col.csv.temp2
SET NGFINAL=UserListFinal.csv
del %NGFINAL% 2>nul
del %NGCSV% 2>nul
set /a c=0
for /f "tokens=1" %%i in (groupList.txt) do (
set /a c=c+1
echo !c!
net group /domain "GG-%%i" |findstr /B /L /V /i /C:"The request" /C:"Group name" /C:"Comment" /C:"Members" /C:"-----" /C:"The command" > %NGCSV%
REM ...Column 1
for /F "tokens=1" %%A in (%NGCSV%) do >>%NGFINAL% echo %%i,%%A
REM ...Column 2
for /F "tokens=2" %%A in (%NGCSV%) do >>%NGFINAL% echo %%i,%%A
REM ...Column 3
for /F "tokens=3" %%A in (%NGCSV%) do >>%NGFINAL% echo %%i,%%A
del %NGCSV%
)
pause
Upvotes: 4