[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to parse csv file and generate batch files

Posted on 2012-03-29
3
Medium Priority
?
737 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 59

Accepted Solution

by:
Bill Prew earned 2000 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 59

Expert Comment

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

~bp
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses
Course of the Month19 days, 4 hours left to enroll

834 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