Windows Shell Script to load csv into variables
I am trying to use Windows built-in shell script to load this file:
hostname1,host_specific_file1
hostname2,host_specific_file2
hostname3,host_specific_file3
.
.
.
Like this:
for /f "tokens=1,2* delims=," %%i in (host-info.txt) do set clientName=%%i; set fileLoc=%%j
Which doesn't work but I want it to go like this:
:loop
For each line, Set the current_hostname=hostnamex and Set the current_file=host_specific_filex
And THEN
DO STUFF
Goto next line, Goto loop
Is there a method for doing this? I can't get my script wrapped around the "Goto next line" or "Handle one line a开发者_运维百科t a time" concept.
Thanks, Chris
You can;
echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2* delims=," %%i in (host-info.txt) do (
set clientName=%%i
set fileLoc=%%j
call:handler
)
goto:eof
:handler
echo client name is !clientName! location is !fileLoc!
goto:eof
Or Using %n notation;
echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2* delims=," %%i in (host-info.txt) do call:handler %%i %%j
goto:eof
:handler
echo client name is %1 location is %2 ...
精彩评论