How to Dynamically Build a .bat file

Posted on 2006-04-12
Last Modified: 2010-04-17
1)Here is my file:

login 'Essbase Admin' 'essbase1';

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


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:


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';

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


Question by:elwayisgod
    LVL 27

    Accepted Solution

    As I said before, install UnxUtils to your Windows from here add to your PATH
    and then convert like this:

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

    where file.txt:

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

    Assisted Solution

    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';


    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.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This is an explanation of a simple data model to help parse a JSON feed
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now