Computing.Net > Forums > Programming > increment variable in batch files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

increment variable in batch files

Reply to Message Icon

Name: MaZ
Date: March 14, 2009 at 01:12:14 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: March 14, 2009 at 01:29:11 Pacific
Reply:

isn't it already diplaying one line at a time???

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


0

Response Number 2
Name: MaZ
Date: March 14, 2009 at 01:50:41 Pacific
Reply:

Thanks for your quick response

but unfortunately it displays them all at once

is there anyway to break them up?

thanks


0

Response Number 3
Name: Judago
Date: March 14, 2009 at 01:56:18 Pacific
Reply:

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.


0

Response Number 4
Name: Mechanix2Go
Date: March 14, 2009 at 03:03:25 Pacific
Reply:

"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


0

Response Number 5
Name: MaZ
Date: March 14, 2009 at 14:01:12 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: Judago
Date: March 14, 2009 at 16:25:06 Pacific
Reply:

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.


0

Response Number 7
Name: MaZ
Date: March 15, 2009 at 00:55:01 Pacific
Reply:

I don't want to echo it but I do want to do some commands before it changes to the next _blah


0

Response Number 8
Name: Judago
Date: March 15, 2009 at 01:17:38 Pacific
Reply:

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.


1

Response Number 9
Name: MaZ
Date: March 15, 2009 at 14:54:52 Pacific
Reply:

Thank you so much

It work perfectly


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: increment variable in batch files

Batch file problem www.computing.net/answers/programming/batch-file-problem/17199.html

Variables in Batch Files www.computing.net/answers/programming/variables-in-batch-files/14347.html

Nesting variables in batch files ? www.computing.net/answers/programming/nesting-variables-in-batch-files-/14334.html