用指定字符串替换指定内容
@echo off
setlocal enabledelayedexpansion
set file=
set /p file= 请输入要操作的文件名称(包括扩展名):
set "file=%file:"=%"
for %%i in ("%file%") do set file=%%~fi
echo.
set replaced=
set /p replaced= 请输入即将被替换的内容:
echo.
set all=
set /p all= 请输入替换字符串:
for /f "delims=" %%i in ('type "%file%"') do (
set str=%%i
set "str=!str:%replaced%=%all%!"
echo !str!>>"%file%"_tmp.txt
)
copy "%file%" "%file%"_bak.txt >nul 2>nul
move "%file%"_tmp.txt "%file%"
start "" "%file%"
用某行内容替换特定字符
@echooff::用A.TXT中的第一行字符,替换B.TXT中的###字符.::再用A.TXT中的第二行字符,替换B.TXT中的@@@字符.::……::如果A.txt第M行中含有在第N行中要替换的内容S(M
统计重复次数并排序的批处理
@echooff::目的:::SearchNet.TXT中每行只有一个数,统计每个数的重复次数,并按照重复次数由高到低排序::思路:::先用sort把所有的数排序,然后统计重复
计算字符串的长度批处理
@echooff&setlocalEnableDelayedExpansion::计算字符串的长度:::::begansetmystr=set/pmystr=输入要计算长度的字符串(直接回车退出):ifnotdefinedmystrgoto:eoffor/l%%iin(0,1,1000)doif"!