Is it possible to edit .Config file using a batch script

前端 未结 2 1234
轮回少年
轮回少年 2021-01-15 03:50

Here some part of the .config file that I have:

    
          
          
                 


        
2条回答
  •  忘掉有多难
    2021-01-15 04:33

    The Batch file below is a preliminary version of a program that achieve what you want. The names of input and output files are hardcoded in the program, but this can be changed to give them in parameters or to automatically process all files selected by a wild-card. The program delete empty lines and fail if the file contain exclamation marks, but these limitations may be fixed if needed.

    @echo off
    setlocal EnableDelayedExpansion
    
    rem Save replacement strings
    set i=0
    :nextParam
       if "%~1" equ "" goto endParams
       set /A i+=1
       set "replace[!i!]=%~1"
       shift
    goto nextParam
    :endParams
    
    rem Process the file
    (for /F "delims=" %%a in (input.txt) do (
       set "line=%%a"
       for /L %%i in (1,1,%i%) do (
          for /F "delims=" %%r in ("!replace[%%i]!") do (
             set "line=!line:%%r!"
          )
       )
       echo !line!
    )) > output.txt
    

    To use this program, give the replacement strings enclosed in quotes as parameters. For example:

    replace.bat "some_name=server 1" "DB_name=A real database on Server 1"
    

    Output:

    
              
              
                
                  
                  
                  
                  
        
    

提交回复
热议问题