increment variable in batch files

March 14, 2009 at 01:12:14
Specs: Windows XP
I am trying to echo one at a time the following txt file
192.168.0.169
192.168.0.173
192.168.0.139

however the batch file I have made, displays them all at once

Set n=
Set _InputFile=list.txt
For /F "tokens=*" %%I IN (%_InputFile%) DO (
Set /a n=1
Set _blah!n!=%%I
Echo %%I
)

Is there anyway to display one at a time?

Thanks


See More: increment variable in batch files

Report •


#1
March 14, 2009 at 01:29:11
isn't it already diplaying one line at a time???

add this line inside the for loop to understand:
ping localhost>nul


Report •

#2
March 14, 2009 at 01:50:41
Thanks for your quick response

but unfortunately it displays them all at once

is there anyway to break them up?

thanks


Report •

#3
March 14, 2009 at 01:56:18
Set /a n+=1 ??? <- Did you forget your plus sign(or whatever operator your using)?


"is there anyway to break them up?"

echo.

This will echo an empty line.


Report •

Related Solutions

#4
March 14, 2009 at 03:03:25
"isn't it already diplaying one line at a time???"

I'm gladf it's not just me.

As posted it sure will put out 1 line at a time.

NOTE: the setting of n and _blah!n! is not doing anything. I wonder what was intended.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#5
March 14, 2009 at 14:01:12
the line is normally
set /a n+=1

I was just mucking around with the code and forgot to change
it back.

Thanks for all of your responses but I don't think I made my
question clear.

after that code is executed I can use the vars %_blah1% to
%_blah3%.

Is the any way to have it in a loop so I don't have to set the
number every time?

eg.

:start
if %_blah!n!%=="" goto EOF
Do somthing
set n=n+1
goto start


Report •

#6
March 14, 2009 at 16:25:06
Since you have a variable with n variables inside why not use a for /l loop.

for /l %%a in (1 1 !n!) do echo !_blah%%a!

Unfortunately the is no easy way to do something similar to create the variables with out mucking around.


Report •

#7
March 15, 2009 at 00:55:01
I don't want to echo it but I do want to do some commands before it changes to the next _blah

Report •

#8
March 15, 2009 at 01:17:38
The echo is just an example to demonstrate, expand/modify to suit your needs.

for /l %%a in (1 1 !n!) do (
<insert esp here> !_blah%%a!
!_blah%%a! !_blah%%a! !_blah%%a!.......
)

Edit:
I don't know about anyone else but if they want me to take a survey (or click no thanks) every time I fix a little mistake I don't think this will last much longer.


Report •

#9
March 15, 2009 at 14:54:52
Thank you so much

It work perfectly


Report •


Ask Question