Batch - use more than 26 tokens in For ?

January 5, 2011 at 05:08:49
Specs: Windows XP
Hi all,

is it possible to use more tokens in For as 26. If yes , what's the name of the vars to use ?

Thanks
Helmut


:: ===== BATCH SCRIPT BEGIN =====
@echo off

setLocal EnableDelayedExpansion

set /a COUNTER=0
set LINE=
FOR /F "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26* delims=;" %%a IN (TEST.csv) DO (
set /a CurLine+=1
set /a count=0
if "%%a"=="pro7" set /a count=1
if "%%b"=="pro7" set /a count=1
if "%%c"=="pro7" set /a count=1
if "%%d"=="pro7" set /a count=1
if "%%e"=="pro7" set /a count=1
if "%%f"=="pro7" set /a count=1
if "%%g"=="pro7" set /a count=1
if "%%h"=="pro7" set /a count=1
if "%%i"=="pro7" set /a count=1
if "%%j"=="pro7" set /a count=1
if "%%k"=="pro7" set /a count=1
if "%%l"=="pro7" set /a count=1
if "%%m"=="pro7" set /a count=1
if "%%n"=="pro7" set /a count=1
if "%%o"=="pro7" set /a count=1
if "%%p"=="pro7" set /a count=1
if "%%q"=="pro7" set /a count=1
if "%%r"=="pro7" set /a count=1
if "%%s"=="pro7" set /a count=1
if "%%t"=="pro7" set /a count=1
if "%%u"=="pro7" set /a count=1
if "%%v"=="pro7" set /a count=1
if "%%w"=="pro7" set /a count=1
if "%%x"=="pro7" set /a count=1
if "%%y"=="pro7" set /a count=1
if "%%z"=="pro7" set /a count=1
set /a COUNTER+=!count!
if !count!==1 set LINE=!LINE!,!CurLine!
)
echo.
echo Found on Line: %LINE% of %CurLine%
echo %COUNTER% - Lines were found.

setlocal disabledelayedexpansion

pause
@REM ===== BATCH SCRIPT END =====


See More: Batch - use more than 26 tokens in For ?

Report •


#1
January 5, 2011 at 05:43:51
Since tokens in FOR /F are case sensitive you can use A-Z doubling the total amount from 26 to 52. Set up some test to check results; anyway this leads to cumbersome code.

Report •

#2
January 5, 2011 at 06:12:08
Thakns IVO,

... that's a good point ... i know that's cumbersome code ... did you know a better way to read out all Colums(67) of an csv file and check it against some criteria ?

Cheers
Helmut


Report •

#3
January 5, 2011 at 06:39:41
@echo off & setlocal EnableDelayedExpansion
set LINE=& set COUNTER=0
for /F "delims=" %%j in (test.csv) do (
  set /A CurLine+=1
  set count=0
  for %%z in (%%j) do if "%%z"=="pro7" set count=1
  set /a COUNTER+=!count!
  if !count!==1 set LINE=!LINE!,!CurLine!
)
echo.
echo Found on Line: %LINE% of %CurLine%
echo %COUNTER% - Lines were found.

setlocal disabledelayedexpansion

pause


Report •

Related Solutions

#4
January 5, 2011 at 08:34:31
.. thanks for your post IVO ...
it's ok if i search the text in each field, but it should be like an table ..
what i try is only a test to figure out how it works.

The 'real' file is within a structure e.g.
Col01 = RecordType
Col10 = ID
Col36 = TypeOfSend
Col42 = RecordID

and so on ...

and a part of this colums i need and the others doesn't matter ...

then i must check the values and in each case i must do other things like count , skip , write log , ...

sorry for my bad understandig , i am a rookie about this stuff ...

Thanks
Helmut


Report •

#5
January 5, 2011 at 11:09:24
Hi Helmut.

Please see http://www.computing.net/answers/pr...

Hope it helps.

Did you Google for an answer before asking the question?


Report •

#6
January 5, 2011 at 11:56:58
Thanks Wahine !

... got advice ... some of this post i will try out and i think a part of this could be helpfull ...

Thank again & take care

Helmut


Report •


Ask Question