2024-04-11 03:35:14
写个批处理脚本,有局限性不能处理UTF8文本, 另外对替换串(CCC AAA)有某些特殊符限制,先 test 再说吧
@echo off
set "f1=test1.txt"
set "f2=test2.txt"
set "cs=CCC=AAA"
cd/d "%~dp0"
echo;正在查找...
for /f "tokens=1* delims=:" %%i in (
'type "%f2%"^|findstr/ng:"%f1%"')do (
echo %%j
set "h=%%j"
call :yky #%%i)
echo;&goto :next
:yky
setlocal enabledelayedexpansion
set "h=!h:%cs%!"
endlocal&set "%1=%h%"&goto :eof
:next
echo 替换并写入文件...
(for /f "tokens=1* delims=:" %%i in (
'type "%f2%"^|findstr/n .*')do (
set "h=%%j"
setlocal enabledelayedexpansion
if defined #%%i set "h=!#%%i!"
>con echo;!h!
echo;!h!
endlocal
))>"new.txt"
:: move "new.txt" "%f2%"
echo;&pause