Link to home
Start Free TrialLog in
Avatar of kmurphy
kmurphyFlag for United States of America

asked on

Using FOR command to process lines in a single file

I feel stupid for asking this but this is something I've not done before.  I've used FOR a lot to parse a command (i.e. dir *., date /t, etc.) to then process that info in some way - reset permissions on a set of folders, set and environment variable to the date and time, etc.
This time I want to take a single file (SvrFile.txt) that contains a list of servers, such as this example:


Shouldn't the FOR command be able to read each line and echo the server names to the screen?  At best I can only get the command to list the text file itself:

          for /f "eol=~" %G IN ("c:\kix32\svrfile.txt") do echo %G

This produces:

          C:\KIX32>echo c:\kix32\svrfile.txt

I can easily script this task - and I have - and I know it's really "old school" but now the question is sticking in my head and I haven't found a pertinent example to follow.

Any help would be appreciated.

Kevin Murphy
Avatar of kmurphy
Flag of United States of America image


I actually realized I should be processing the find command on this file and that does give me the contents when I parse "find /V "" svrfile.txt"

so here's how I get the list of the lines in the file:
for /F "eol=~" %G IN ('find /V "" c:\kix32\svrfile.txt') do echo %G
Avatar of NVIT
Other ways...

for /f %a in ('type "c:\kix32\svrfile.txt"') do echo %a
for /f %a in (c:\kix32\svrfile.txt) do echo %a

Open in new window

Avatar of Bill Prew
Bill Prew

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial