batch get csv values and save them into variables for further use -


i want extract values of file this:

4564,cde0 7578,kernel 123465,performer info,kernel 

i thought putting data csv file easiest option, if there easier way values in variables, open suggestions. have way more 4 lines...

i want use values: line 1 need 4564 , cde0 in separate variables. put them in script , continue line 2 , on.

i have found several threats deal columns , have following code:

for /f "tokens=1-2 delims=," %%a in (test.csv) (@echo %%a %%b)  

but shows me content without ",".

is there way go through line , put 2 values 2 variables?

if think easiest way go through csv file loop extract values variables, use them , continue next line, not familiar batch don't know if best way so.

thank you

at case, multi-dimensional array trick. since batch don't have array feature, can make ourself! this:

@echo off setlocal enabledelayedexpansion  set var1=0  /f "tokens=1* delims=," %%a in (text.csv) (     set var2=0     set array[!var1!][!var2!]=%%a     set /a var2+=1     set array[!var1!][!var2!]=%%b     set /a var1+=1 )  echo first column, first element: %array[0][0]% echo first column, second element: %array[0][1]% echo second column, first element: %array[1][0]% echo second column, second element: %array[1][1]%  pause >nul 

let me briefly expalin what's going on here. multi-dimensional array array containing 1 or more arrays. common array looks array[0], indicates 1st element since element counts 0.

while multi-dimensional array array[0][0] indicates 1st array's 1st array (may sounds confusing). think of array[0][0] line, array[0][0] column, array[1][2] indicates 2nd line, 3rd column. (*draw table , practice)


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -