Read a file and store the values in a varibale

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
naraen87
Posts: 17
Joined: 21 Dec 2017 06:41

Read a file and store the values in a varibale

#1 Post by naraen87 » 27 Feb 2018 05:10

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.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

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

#2 Post by penpen » 03 Mar 2018 09:40

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

Post Reply