Batch file: How to replace “=” (equal signs) and a string variable?

前端 未结 6 1814
孤独总比滥情好
孤独总比滥情好 2020-12-10 07:39

Besides SED, how can an equal sign be replaced? And how can I use a string variable in string replacement?

Consider this example:

For /F \"tokens=*\"         


        
6条回答
  •  南笙
    南笙 (楼主)
    2020-12-10 07:59

    Why not use Edlin? I could not find a way to do this with one initial file and no errors from Edlin, but just ignore them with NUL:. Strangly, the TYPE %0 includes the whole file even if there's an end of file character between the = and !, using TYPE on the batch file after it has run will not work the same way.

    @ECHO OFF
    GOTO skip
    1,1r=!
    e
    :skip
    
    SET "new==old============="
    
    ECHO %new% > %TEMP%\var.tmp
    TYPE %0 > %TEMP%\edlin.tmp
    
    EDLIN %TEMP%\var.tmp < %TEMP%\edlin.tmp > NUL:
    
    SET /P newnew=<%TEMP%\VAR.TMP
    ECHO %newnew%
    
    ERASE %TEMP%\VAR.TMP
    ERASE %TEMP%\VAR.BAK
    ERASE %TEMP%\edlin.tmp
    

提交回复
热议问题