Page 1 of 1

Read a file and store the values in a varibale

Posted: 27 Feb 2018 05:10
by naraen87
My CSV file looks like

Code: Select all

Environment,non-cluster
Server1,10.66.216.141
GDrvie_Build,\\ukgswtowb10\g$\CAM8\CAM8_6.20.8.4
Change_in_MysysProperty,ORF2_v6.20.8.9
In the above csv
First I've to check the first column If its Enviroment then set the respective second column value to some variable called env
In the same manner I've to check all and store their respective to variables servername,buildlcoation and buildversion
Could anyone please help.

Re: Read a file and store the values in a varibale

Posted: 03 Mar 2018 09:40
by penpen
This might help you:

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
set "source=sample.csv.txt"

set "$Environment=env"
set "$Server1=servername"
set "$GDrvie_Build=buildlcoation"
set "$Change_in_MysysProperty=buildversion"

for /F "usebackq tokens=1* delims=," %%a in ("%source%") do set "!$%%~a!=%%~b"

set "env"
set "servername"
set "buildlcoation"
set "buildversion"

goto :eof
penpen