Batch file question

G

Guest

1) I have a command I'm trying to run (test before putting it in a batch
file) which I basically want to run the same command but with different names
that are contained in a text file with single line entry's. The file I have
(Textfile.txt) contains:

computer1
computer2
computer3
computer4

2) The command I'm trying to run is:
FOR /F "tokens=1" %G IN (C:\Textfile.txt) DO echo %g

3) The output I'm getting is:

C:\>echo %g%g
C:\>echo %g%g
C:\>echo %g%g
C:\>echo %g%g

Eventually I'll be changing the echo command to something else, but what am
I doing wrong that the echo command is only putting out what I told it yet
it's cycling through the number of records in the file correctly?
 
J

Jerold Schulman

1) I have a command I'm trying to run (test before putting it in a batch
file) which I basically want to run the same command but with different names
that are contained in a text file with single line entry's. The file I have
(Textfile.txt) contains:

computer1
computer2
computer3
computer4

2) The command I'm trying to run is:
FOR /F "tokens=1" %G IN (C:\Textfile.txt) DO echo %g

3) The output I'm getting is:

C:\>echo %g%g
C:\>echo %g%g
C:\>echo %g%g
C:\>echo %g%g

Eventually I'll be changing the echo command to something else, but what am
I doing wrong that the echo command is only putting out what I told it yet
it's cycling through the number of records in the file correctly?

In a batch file, you must use %% instead of %.

FOR /F "tokens=1" %%G IN (C:\Textfile.txt) DO echo %%G

The case of %%G in both occurences should be the same.


Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
G

Guest

I made both the same and tried it, "C:\>FOR /F "tokens=1" %%G IN
(C:\Textfile.txt) DO echo %%G

And received this:

%%G was unexpected at this time.

does that error shed any light?
 
G

Guest

Solved my problem there, I realized that I was using two "%" signs, running
from a command line I should've been using only one..... worked like a charm
when I put it in.... Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top