Windows下cmd bat脚本实现文件字符串批量替换
@ECHO OFF
SET SRC=%1
SET DST=%2
SET OLD=%3
SET NEW=%4
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /F "TOKENS=*" %%S IN (%SRC%) DO (
SET "TMP=%%S"
IF NOT !TMP!.==. (
SET "TMP=!TMP:%OLD%=%NEW%!"
@ECHO !TMP!>>TMP.TMP
)
)
MOVE TMP.TMP %DST%
使用方法如下:(第四个参数不填写就是自动替换为空)
rep.bat iconv.h.in iconv.h @DLL_VARIABLE@