回复 1# winbat
测试于 win7 64位 | @echo off & setlocal enabledelayedexpansion | | | | >result.txt cd. | | | | for /f "tokens=1,2 delims=-" %%a in (截取号码段.txt) do ( | | | | set "a=%%a" & set "b=%%b" & set "name=!a:~0,4!" | | | | for /f tokens^=2delims^=: %%i in ('find /c /v "" "!name!.txt"') do set /a "lb=0, ub=%%i, sk=ub/2" | | call :PAfterLines "!name!.txt" "!a:~0,13!" 0 | | | | call :writeTemp "!name!.txt" tmpfile new | | sort /r tmpfile /o tmpfile | | | | for /f tokens^=2delims^=: %%i in ('find /c /v "" tmpfile') do set /a "lb=0, ub=%%i, sk=ub/2" | | call :PAfterLines tmpfile "!b:~0,13!" -1 | | call :writeTemp tmpfile result.txt | | ) | | sort result.txt /o result.txt | | del tmpfile | | pause | | exit | | | | | | :writeTemp infile outfile new | | if "%3" neq "" >"%~2" cd. | | if !sk! equ 0 (copy "%~2" + "%~1" "%~2" & exit /b) | | >>"%~2" (for /f skip^=%sk% %%a in (%~s1) do echo;%%a) | | exit /b | | | | | | REM order = 0 升序 order = -1 反序 | | :PAfterLines file str order | | if !sk! equ 0 exit /b | | for /f skip^=%sk% %%a in (%~1) do ( | | if !lb! geq !ub! exit /b | | if "%%a" gtr "%~2" ( | | set /a "ub=(~%3 & sk)|(%3 & ub), lb=(~%3 & lb)| (%3 & (sk+^!(lb-sk))), sk=(lb+ub)>>1" | | call :PAfterLines %~1 %~2 %3 & exit /b | | ) else if "%%a" equ "%~2" ( exit /b | | ) else ( | | set /a "lb=(~%3 & (sk+^!(lb-sk)))|(%3 & lb), ub=(~%3 & ub)|(%3 & sk), sk=(lb+ub)>>1" | | call :PAfterLines %~1 %~2 %3 & exit /b | | ) | | ) | | exit /bCOPY |
|