考虑再三为了代码不至于太复杂还是生成一个临时文件好些:
@echo off&setlocal enabledelayedexpansion
for /f "tokens=3 delims= " %%i in (1.txt) do set str=!str! n%%in
for %%i in (!str!) do set a=%%i&call :lp
set str=!str:n=!
for %%a in (!str!) do (
for /f "tokens=1,2,3,4* delims= " %%i in (1.txt) do (
if %%a equ %%k echo %%i %%j %%k %%l %%m>>2.txt
)
)
del /q 1.txt&ren 2.txt 1.txt
echo 排序完成!
pause>nul&goto :eof
:lp
for %%i in (!str!) do (
set b=%%i&set b=!b:~1,-1!&set c=%a:~1,-1%
if !b! gtr !c! (
set str=!str:%a% =!
set str=!str:%%i=%%i %a%!
)
)
附测试文本:
a b 1 c d e
a b 2 c d e
a b 3 c d e
a b 4 c d e
a b 5 c d e
a b 6 c d e
a b 7 c d e
a b 8 c d e
a b 9 c d e
a b 10 c d e
a b 11 c d e
a b 12 c d e
a b 13 c d e
a b 14 c d e
a b 15 c d e
a b 16 c d e
a b 17 c d e
a b 18 c d e
a b 19 c d e
a b 20 c d e
[
Last edited by zw19750516 on 2008-5-9 at 12:16 AM ]
批处理之家新域名:www.bathome.net