Batch script to find and replace a string in text file within a minute for files up to 12 MB

前端 未结 6 872
逝去的感伤
逝去的感伤 2020-12-02 10:13

I have written a batch script to replace a string in text file.

Following is the script.

@echo off &setlocal
set \"search=%1\"
set \"replace=%2\"         


        
6条回答
  •  隐瞒了意图╮
    2020-12-02 10:44

    Try this:

    @echo off &setlocal
    setlocal enabledelayedexpansion
    
    set "search=%1"
    set "replace=%2"
    set "textfile=Input.txt"
    set "newfile=Output.txt"
    (for /f "delims=" %%i in (%textfile%) do (
        set "line=%%i"
        set "line=!line:%search%=%replace%!"
        echo(!line!
    ))>"%newfile%"
    del %textfile%
    rename %newfile%  %textfile%
    endlocal
    

提交回复
热议问题