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

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

    How about this, folks?

    set search=%1
    set replace=%2
    set textfile=Input.txt    
    
    set line1=with open('%textfile%', 'rw') as f:
    set line2=f.write(f.read().replace('%search%', '%replace%'))
    python -c "%line1%%line2%"
    

    Muhahaha


    Edit:

    In a crazy oneliner

    python -c "with open('%textfile%', 'rw') as f: f.write(f.read().replace('%search%', '%replace%'))"
    

提交回复
热议问题