2

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%
3
  • 2
    could you please simplify your question? what is exactly happening vs what you expected? Commented Oct 6, 2014 at 8:49
  • I'm not sure I can. This code is basically two Google searches combined. When I cut a bunch of stuff out (like the inner loops) I get the %NGFINAL% output (although nothing like as I would want). I've now changed to my original, I guess it's easier to find a "continue" equivalent rather than why the loop breaks Commented Oct 6, 2014 at 9:29
  • Possible duplicate of "continue" equivalent command in nested loop in Windows Batch Commented Feb 27, 2017 at 3:43

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks that works although I'd rather not have the end of the workflow in the middle. Is there no continue equivalent to jump to the next iteration then?
It does iterate through the grouplist.txt file - what might confuse you it is that the counter only executes once, as it wasn't clear in your code what it was supposed to be doing. See the edited answer above, plus an alternate code which should work the same way.
I know it iterated. By "continue" I mean, before the loop would still call :eof each iteration. I was wondering if there was a way to keep the :eof section at the bottom and before that have a command saying "don't continue reading down the file, begin the next iteration of the loop instead" like the "continue;" command does in most languages. I like that 1 line findstr though, will try to incorporate
My edited version of your first script shows you how to do what you asked.
:eof is not recommended as a label name but any other label name could be used. People generally recommend to avoid using names of commands as label names too, as it can be confusing.
|
2

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
)

4 Comments

probably this works in your case, but generally the approach seems to be wrong - goto disrupts the execution flow
FYI should be echo continue this loop > nul as mentioned in your description not in your code. note the single 'l' in 'nul'. 2 'l's in 'null' just creates a file instead. I couldn't contribute the edit :(
@Larry got it! 10x. Fixed
The goto :next doesn't implement a continue, it's a break

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.