batch file to search and replace a string

后端 未结 3 1667
不知归路
不知归路 2021-01-22 19:38

I need a batch file that should search the PC for all files issued today named as \"example.ini\" and replaces a string which will be in the second line of \"example.ini\", it s

3条回答
  •  心在旅途
    2021-01-22 20:26

    Test this on some sample files.

    It will change the example.ini files on c:\ and in subdirectories which contain SERVER_IP=212.83.63.108 and will change it to SERVER_IP=222.22.22.222

    It uses a helper batch file called repl.bat from - https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

    Place repl.bat in the same folder as the batch file.

    @echo off
    for /r c:\ %%a in (example.ini) do (
    find "SERVER_IP=212.83.63.108" <"%%a" >nul && (
        echo processing "%%a"
        type "%%a"|repl "SERVER_IP=212\.83\.63\.108" "SERVER_IP=222.22.22.222" >"%%a.tmp"
        move /y "%%a.tmp" "%%a" >nul
        )
    )
    

提交回复
热议问题