Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Script to parse csv file and generate batch files

Posted on 2012-03-29
3
731 Views
Last Modified: 2012-03-29
I have to create a set of batch files for various locations in our firm.  The purpose of the batch files is to create a batch file that can be run to set system-level environment variables on systems.

Here is the CSV format:

location,server,state,db1,db2
downtown,downtownsrv,dc,databasea,databaseb
uptown,uptownsrv,dc,databasea

I would like to have the script to read a line, in the CSV, and create a batch file with the following contents:

setx location=downtown
setx server=downtownsrv
setx state=dc
setx db1=databasea
setx db2=databaseb

Once the bach file is created, I'd like to have the batch file copied to a server location.  Once the copy is complete, the script should go to the next line and do the same thing at a different location until all locations are complete.  The script needs to be flexible enough to add more columns in the future.  

The reason I am creating these batch scripts is so I can use our desktop management suite to run the batch script on our systems.  We cannot use login scripts because we need to have these settings set regardless of whether a user is logged in or not.  Group policy is also not an option, at this moment.
0
Comment
Question by:fbrsupport
  • 2
3 Comments
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 37782299
Working on a mobile device, but I'll try to get this started.

@echo off
Set CsvFile=c:\temp\csvfile.csv
For /F "skip=1 tokens=1-5 delims=," %%A in (%CsvFile%) do (
  Echo set Location=%%A>%OutFile%
  Echo set server=%%B>>%OutFile%
  Echo set start=%%C>>%OutFile%
  Echo set db1=%%D>>%OutFile%
  Echo set db2=%%E>>%OutFile%
  Copy %outfile% d:\serverloc
)

Open in new window

0
 

Author Closing Comment

by:fbrsupport
ID: 37782690
That was perfect.  I think I was over thinking the solution.  I made some slight modifications to the script but thanks for getting me started.  For the copy command I used xcopy and used the server value in the destination.
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 37782838
Great, so glad that helped.

~bp
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question