批处理替换文件夹下所有txt中的指定内容A为B,而且空白行需要保留,实现了替换功能但是没有保留空白行
@echooffsetlocalenabledelayedexpansionfor/f"delims="%%iin('dir/b"*.txt"')do(for/f"ski...
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b "*.txt"') do (
for /f "skip=2 delims=" %%a in ('find /v "%%" "%%i"') do (
set "word1=%%a"
set "word1=!word1: A=B!"
rem 被替换内容A=替换内容B
echo,!word1! >>"%%~ni_tmp.txt"
)
del "%%i" /f /q
ren "%%~ni_tmp.txt" "%%i"
)
pause 展开
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b "*.txt"') do (
for /f "skip=2 delims=" %%a in ('find /v "%%" "%%i"') do (
set "word1=%%a"
set "word1=!word1: A=B!"
rem 被替换内容A=替换内容B
echo,!word1! >>"%%~ni_tmp.txt"
)
del "%%i" /f /q
ren "%%~ni_tmp.txt" "%%i"
)
pause 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询