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

前端 未结 6 863
逝去的感伤
逝去的感伤 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:40

    A variant using Bat/Powershell (need .net framework):

    replace.bat :

    @echo off
    
    call:DoReplace "Findstr" "replacestr" test.txt test1.txt
    exit /b
    
    :DoReplace
    echo ^(Get-Content "%3"^) ^| ForEach-Object { $_ -replace %1, %2 } ^| Set-Content %4>Rep.ps1
    Powershell.exe -executionpolicy ByPass -File Rep.ps1
    if exist Rep.ps1 del Rep.ps1
    echo Done
    pause
    

提交回复
热议问题