Page 1 of 1

How to lift up this limitation...

Posted: 19 Dec 2017 16:18
by goodywp
Hi,

I have a data file as pkg_data.txt
NAR_Infra, T592,08693,-0101,T500,Tetra_TD_Desk5000,8295010512_TSA.P3A ,TELIUM3\TSA ,T501-08665-0102,T501-08681-0100,no_fk

Now I have this script as below:

Code: Select all


@echo off
  for /f "tokens=1-12 delims=," %%A in (pkg_data.txt) do call :EachLine %%A %%B %%C %%D %%E %%F %%G %%H %%I %%J %%K %%L
goto :eof 
:EachLine 

echo var1=%1
echo var2=%2
echo var3=%3
echo var4=%4
echo var5=%5
echo var6=%6
echo var7=%7
echo var8=%8
echo var9=%9
echo var10=%10
echo var11=%11

After I run, I only got this results as below:
var1=NAR_Infra
var2=T592
var3=08693
var4=-0101
var5=T500
var6=Tetra_TD_Desk5000
var7=8295010512_TSA.P3A
var8=TELIUM3\TSA
var9=T501-08665-0102
var10=NAR_Infra0
var11=NAR_Infra1

It seems that there is a limitation for this ?
after var9 it did not show the exactly results it should be...
var10=T501-08681-0100
var11=no_fk

Is any way to lift this limit????

Thanks!!!

Re: How to lift up this limitation...

Posted: 19 Dec 2017 16:33
by Squashman
Correct. You only have 1 to 9 for arguments. You can still send more than 9 arguments, you just need to use the SHIFT command to access them.

Two options for you.

Code: Select all

@echo off

for /f "tokens=1-11 delims=," %%A in (pkg_data.txt) do (
	call :EachLine "%%~A" "%%~B" "%%~C" "%%~D" "%%~E" "%%~F" "%%~G" "%%~H" "%%~I" "%%~J" "%%~K"
	echo ---------------
	call :EachLine2 "%%~A" "%%~B" "%%~C" "%%~D" "%%~E" "%%~F" "%%~G" "%%~H" "%%~I" "%%~J" "%%~K"
)
pause
GOTO :EOF

:EachLine
setlocal enabledelayedexpansion
SET "i=1"
FOR %%A IN (%*) DO (
	SET "var!i!=%%~A"
	set /A "i+=1"
)
set var
endlocal
GOTO :EOF

:EachLine2
set "var1=%~1"
set "var2=%~2"
set "var3=%~3"
set "var4=%~4"
set "var5=%~5"
set "var6=%~6"
set "var7=%~7"
set "var8=%~8"
set "var9=%~9"
shift
set "var10=%~9"
shift
set "var11=%~9"
set var
GOTO :EOF
Output

Code: Select all

var1=NAR_Infra
var10=T501-08681-0100
var11=no_fk
var2= T592
var3=08693
var4=-0101
var5=T500
var6=Tetra_TD_Desk5000
var7=8295010512_TSA.P3A
var8=TELIUM3\TSA
var9=T501-08665-0102
---------------
var1=NAR_Infra
var10=T501-08681-0100
var11=no_fk
var2= T592
var3=08693
var4=-0101
var5=T500
var6=Tetra_TD_Desk5000
var7=8295010512_TSA.P3A
var8=TELIUM3\TSA
var9=T501-08665-0102
Press any key to continue . . .

Re: How to lift up this limitation...

Posted: 20 Dec 2017 08:41
by goodywp
Squashman wrote:
19 Dec 2017 16:33
Correct. You only have 1 to 9 for arguments. You can still send more than 9 arguments, you just need to use the SHIFT command to access them.

Two options for you.

Code: Select all

@echo off

for /f "tokens=1-11 delims=," %%A in (pkg_data.txt) do (
	call :EachLine "%%~A" "%%~B" "%%~C" "%%~D" "%%~E" "%%~F" "%%~G" "%%~H" "%%~I" "%%~J" "%%~K"
	echo ---------------
	call :EachLine2 "%%~A" "%%~B" "%%~C" "%%~D" "%%~E" "%%~F" "%%~G" "%%~H" "%%~I" "%%~J" "%%~K"
)
pause
GOTO :EOF

:EachLine
setlocal enabledelayedexpansion
SET "i=1"
FOR %%A IN (%*) DO (
	SET "var!i!=%%~A"
	set /A "i+=1"
)
set var
endlocal
GOTO :EOF

:EachLine2
set "var1=%~1"
set "var2=%~2"
set "var3=%~3"
set "var4=%~4"
set "var5=%~5"
set "var6=%~6"
set "var7=%~7"
set "var8=%~8"
set "var9=%~9"
shift
set "var10=%~9"
shift
set "var11=%~9"
set var
GOTO :EOF
Output

Code: Select all

var1=NAR_Infra
var10=T501-08681-0100
var11=no_fk
var2= T592
var3=08693
var4=-0101
var5=T500
var6=Tetra_TD_Desk5000
var7=8295010512_TSA.P3A
var8=TELIUM3\TSA
var9=T501-08665-0102
---------------
var1=NAR_Infra
var10=T501-08681-0100
var11=no_fk
var2= T592
var3=08693
var4=-0101
var5=T500
var6=Tetra_TD_Desk5000
var7=8295010512_TSA.P3A
var8=TELIUM3\TSA
var9=T501-08665-0102
Press any key to continue . . .
Thank you so much !!!! :)

Re: How to lift up this limitation...

Posted: 07 Jan 2018 00:25
by thefeduke
This an oldie but goodie:
DOStips wrote:Rem Posted: Sun Jan 22, 2012 9:02 pm by dbenham
Rem Post subject: Re: foolproof counting of arguments
Rem Start http://www.dostips.com/forum/viewtopic. ... 002#p13002
I chopped this from one of my scripts as an example:

Code: Select all

@Echo Off&SetLOCAL EnableDelayedExpansion &Rem.and keep environment uncluttered.
    Echo.
    Set /P "Chose=Enter one or more arguments: "
    >Nul Call :ArgCtr %Chose%
    For /L %%L In (1,1,%ArgCnt%) Do (
        Echo.%%~L - !arg[%%L]!
    )
    Echo.
    Set <nul /P "= Press any key to continue after viewing list . . . "
    >Nul Pause
    Echo.
Set arg
    Exit /B

:ArgCtr
set argCnt=1
:getArgs
Rem Posted: Sun Jan 22, 2012 9:02 pm by dbenham
Rem Post subject: Re: foolproof counting of arguments
Rem Start http://www.dostips.com/forum/viewtopic.php?p=13002#p13002
Rem this[ArgCtr.bat] cloned from Getargs.bat Nov 2,2017 by thefeduke
>"%temp%\getArg.txt" <"%temp%\getArg.txt" (
  setlocal disableExtensions
  set prompt=#
  echo on
  for %%a in (%%a) do rem . %1.
  echo off
  endlocal
  set /p "arg[%argCnt%]="
  set /p "arg[%argCnt%]="
  set "arg[%argCnt%]=!arg[%argCnt%]:~7,-2!"
  if defined arg[%argCnt%] (
    set /a argCnt+=1
    shift /1
    goto :getArgs
  ) else set /a argCnt-=1
)
del "%temp%\getArg.txt"
Exit /B
or you could make it work from actual arguments.

John A

Re: How to lift up this limitation...

Posted: 09 Jan 2018 14:20
by goodywp
thefeduke wrote:
07 Jan 2018 00:25
This an oldie but goodie:
DOStips wrote:Rem Posted: Sun Jan 22, 2012 9:02 pm by dbenham
Rem Post subject: Re: foolproof counting of arguments
Rem Start http://www.dostips.com/forum/viewtopic. ... 002#p13002
I chopped this from one of my scripts as an example:

Code: Select all

@Echo Off&SetLOCAL EnableDelayedExpansion &Rem.and keep environment uncluttered.
    Echo.
    Set /P "Chose=Enter one or more arguments: "
    >Nul Call :ArgCtr %Chose%
    For /L %%L In (1,1,%ArgCnt%) Do (
        Echo.%%~L - !arg[%%L]!
    )
    Echo.
    Set <nul /P "= Press any key to continue after viewing list . . . "
    >Nul Pause
    Echo.
Set arg
    Exit /B

:ArgCtr
set argCnt=1
:getArgs
Rem Posted: Sun Jan 22, 2012 9:02 pm by dbenham
Rem Post subject: Re: foolproof counting of arguments
Rem Start http://www.dostips.com/forum/viewtopic.php?p=13002#p13002
Rem this[ArgCtr.bat] cloned from Getargs.bat Nov 2,2017 by thefeduke
>"%temp%\getArg.txt" <"%temp%\getArg.txt" (
  setlocal disableExtensions
  set prompt=#
  echo on
  for %%a in (%%a) do rem . %1.
  echo off
  endlocal
  set /p "arg[%argCnt%]="
  set /p "arg[%argCnt%]="
  set "arg[%argCnt%]=!arg[%argCnt%]:~7,-2!"
  if defined arg[%argCnt%] (
    set /a argCnt+=1
    shift /1
    goto :getArgs
  ) else set /a argCnt-=1
)
del "%temp%\getArg.txt"
Exit /B
or you could make it work from actual arguments.

John A
Thank you so much!