批处理文件搜索和替换字符串 [英] batch file to search and replace a string

查看:175
本文介绍了批处理文件搜索和替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要应搜索PC为今天发布命名为example.ini的所有文件,并替换这将是在example.ini第二行的字符串一个批处理文件,就应更换

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 should replace

SERVER_IP = 111.111.111.111 与其他服务器的IP SERVER_IP = 222.222.222.222

SERVER_IP=111.111.111.111 with another server ip SERVER_IP=222.222.222.222

这怎么可能?

推荐答案

这是一些示例文件进行测试。

Test this on some sample files.

这将改变 example.ini 文件C:\\ 并在其中包含<$ C $子目录C> = SERVER_IP 212.83.63.108 键,将其更改为 SERVER_IP = 222.22.22.222

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

它使用名为 repl.bat 从助手批处理文件 - https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

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

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
    )
)

这篇关于批处理文件搜索和替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆