Can I Edit a CMD file with another CMD file or script? RRS feed

  • Question

  • I have created a cmd file that copies files to the workstation from a server location.   However, the server name for mapping a drive and user login and password will vary with each branch office. 

    What I want to do is to have a cmd file that the tech can launch from a flash drive and will be prompted for the information and once the tech types the information, the cmd file would launch and edit the remote cmd file with the variable information.  

    For example, I use set /P user= type in login name in the cmd file.   What I want from the editing cmd file is after the user name is typed the cmd file would launch and it would edit the remote cmd file with the typed inforation and put it int he line:  set /P user= (actually put in the name here) so when the remote cmd file launches, it already has the user name needed to login.

    Thank you in advance for your time

    Friday, October 30, 2009 9:28 PM


  • Search for and download a windows version of SED.exe.  Sed will do search and replace of text in files to create new files, but trying to get the information from the user to the SED script file may still be a problem.  A better approach would be to pre-create all the "Site Configurations" into the batch file (file server, username and password, etc) then have the user simply run a command line syntax format command to specify which configuration optiont to run.

    Simplistic Explination of Syntax for SED.Exe:

    s = Search and replace
    General syntax for "s" is s/searchtext/replacetext/g
    g = indicates "global" or all occurances of.

    / = is a syntax seperator indicating text being searched for, and can be used without the
     "Search and Replace" or (s) indicator shown above.

    [Aa] = Means letter "A" OR "a" in exact position. Can be as many letters as you want. 
     This is called a "Set"

    . = Match any Character in that exact position within a string. 
     (example: /te.t/ would match "test" and "text"

    \\ = \ becase SED uses "\" as an escape character to indicate special character (See below).
     Therefore to represent 1 "\" to search for or replace with input "\\"


    Good Luck.


    • Proposed as answer by Gunner999 Friday, November 6, 2009 3:26 AM
    • Marked as answer by IamMred Friday, January 8, 2010 6:29 AM
    Tuesday, November 3, 2009 4:38 AM