batch file to strip numbers from filename and pad to two digits

Posted by ss2k on Server Fault See other posts from Server Fault or by ss2k
Published on 2011-06-25T14:14:35Z Indexed on 2011/06/25 16:23 UTC
Read the original article Hit count: 186

Filed under:

I have a text file with a list of server names (servers.txt) that looks something like this:

server1 server2 server3

I have a feeling this can be done with the FOR command as I use that to perform an action on each name in the file, but I'm not quite sure how to use the delimiters to accomplish this.

for /F "tokens=*" %%G in (servers.txt) do (  
  SET machinenum = <magic here>
  ECHO %machinenum%
)

expected output

01 02 03

© Server Fault or respective owner

Related posts about batch-file