写个批处理,统计一个文本中的数字出现次数,按从少到多顺序排列。
如文本1.txt里的内容为:
5 2 5 4 6 1 2 5 0 8 7 9 5 4 6 2 0 8 9 7 6 0 4 2 5 1 。。。。。。。。。
内容比较多,要求统计在0后面出现数字从少到多次序排列出来
如:
0后面出现的数字:1为0次,2为0次,3为0次,5为0次,6为0次,7为0次,9为0次,4为1次,8为2次。。。。。。。。。;
1后面出现的数字:。。。。。。。。。。。。。。。。。
我刚接触,很多都看不懂,不过我知道有段代码可以借鉴:
@echo off
setlocal enabledelayedexpansion
:i
for /f "delims=: tokens=1" %%i in ('findstr /n "." 1.txt') do (
set end=%%i
)
set /a end-=6
set a=1
for /f "tokens=*" %%i in ('more +%end% 1.txt') do (
set a!a!=%%i
set /a a+=1
)
set str=
set ok=
for /l %%i in (0,1,9) do (
call :set %%i
set n%%i=!back!
if !back!==0 set "str=%%i !str!"
)
md tmp
cd tmp
for /l %%i in (0,1,9) do if not !n%%i!==0 (
for /l %%a in (1,1,!n%%i!) do (echo.a>>%%i)
)
set /p=出现频率:<nul
for /f "tokens=*" %%i in ('dir /b /o:-s') do (
set /p=%%i-!n%%i!次 <nul
)
cd..
rd /s /q tmp>nul
echo.
echo.没出现过的数字有:%str%
echo.按任意键重新运行一次。
pause>nul
goto :i
:set
set back=-6
for /l %%i in (1,1,6) do (
set "b%%i=!a%%i:%1=t,t!"
for %%a in (!b%%i!) do set /a back+=1
)
goto :eof
高手帮我分析一下吧,谢谢~! |