How to Dynamically Build a .bat file

1)Here is my file:

login 'Essbase Admin' 'essbase1';

export database Alloc.Alloc data to data_file 'C:\EssbaseBackup\Monday\Export\Alloc.txt';


exit;

2)The 'login' and 'exit' lines are static.

3) The lines in between need to be dynamic.  For instance I need a way to go out to a location which is another file named 'databases.txt'.  This file would contain the following lines and these lines could change every day:

Alloc.Alloc
isgit.isgit
z_test.z_test

4) I need the script to build my file in Step 1 to include 2 lines total. One for the Alloc.Alloc and one for the isgit.isgit.  It needs to ignore adding a line when the line in the file in Step 3 begins with 'z_'

5) The end result file would be:

login 'Essbase Admin' 'essbase1';
export database Alloc.Alloc data to data_file 'C:\EssbaseBackup\Monday\Export\Alloc.txt';
export database isgit.isgit data to data_file 'C:\EssbaseBackup\Monday\Export\isgit.txt';
exit;

6) Then save this .bat file using same name as before.


Thanks,

Sam
elwayisgodAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NopiusCommented:
As I said before, install UnxUtils to your Windows from here http://unxutils.sourceforge.net/ add to your PATH
and then convert like this:

gawk -F. -f convert.awk file.txt

where file.txt:
Alloc.Alloc
isgit.isgit
z_test.z_test

convert.awk is:
BEGIN{
print "login 'Essbase Admin' 'essbase1';"
}
{
print "export database " $1 FS $2 " data to data_file 'C:\\EssBaseBackup\\Monday\\Export\\" $1 ".txt;'"
}
END{print "exit;"}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bigjosh2Commented:
So, this simple 2 line batch file will almost do exactly what you want...

login 'Essbase Admin' 'essbase1';
for /f %1 in (databases.txt) do export database %1 data to data_file 'C:\EssbaseBackup\Monday\Export\%1.txt';

..except,

1) The output files will be named "Alloc.Alloc.txt" instead of "Alloc.txt" etc. This might be ok for your application.

2) It will not ignore the "Z_" line, which again might be ok in your application, depending on what the EXPORT command does when passed an invalid name.

Both #1 and/or #2 can be fixed with a bit more work. Let me know if you need to see how.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.