@echo off
setlocal enabledelayedexpansion
echo 替换记事本中值
echo.
echo 作者:phenix
echo.
echo 邮箱:279682817@qq.com
echo.
set /p path=请输入文件完整路径,比如c^:\a.txt:
set /p str=请输入搜索字符串:
set /p repstr=请输入替换字符串:
set rownum=1
for /f "usebackq tokens=*" %%a in ("!path!") do (
set lines=
for /f "usebackq skip=3 tokens=1,2 delims= " %%A in (`C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell -command "& {select-string -path "!path!" "!str!"|format-table linenumber,line}"`) do (
if "%%A" equ "!rownum!" (
set lines=%%B
)
)
if "!lines!" neq "" (
call set "val=%%lines:!str!=!repstr!%%"
echo !val!>>%userprofile%\desktop\替换.txt
) else (
echo %%a>>%userprofile%\desktop\替换.txt
)
set /a rownum+=1
)
echo 替换完毕!
pause
exit
10-03
2533
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)