Passing tokens beyond the restricted limit via for

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Passing tokens beyond the restricted limit via for

#1 Post by Cleptography » 25 May 2011 17:07

An oldie but a goody. There are plenty of work arounds to this question already in existence, just sharing one that I had come up with some time ago.

Code: Select all

@echo off
 setlocal

set file=%~1
set token=1

for /f "tokens=*" %%- in (%file%) do (
    set str=%%-&&call :NEXT
)
goto :eof

:NEXT
for /f "tokens=1,*" %%a in ("%str%") do (
    echo.[%%a] is the %token% token
    set str=%%b
)
set /a token=%token%+1
if "%str%"=="" goto :eof
goto :NEXT

Post Reply