本帖最后由 CrLf 于 2012-11-4 21:36 编辑
awk 和 sed,话说使用临时文件好像比管道快:- gawk "{print 100000+length($0) $0}" 1.txt|sort /r|sed "s/.\{6\}//"
复制代码 若改造楼主提供的代码就是:- @echo off&setlocal enabledelayedexpansion
- for /l %%a in (1 1 50) do set "key=!key!."
- (for /l %%a in (0 1 49) do (
- findstr /x "!key:~%%a!" 1.txt
- ))>b.txt
复制代码 vbs 的话,不知道用 ado 会不会快点,这个还是 demon 或者 powerbat 等人比较擅长:- Set fso = CreateObject("Scripting.FileSystemObject")
- Set rs = CreateObject("ADODB.RecordSet")
-
- rs.Fields.Append "length",14,3
- rs.Fields.Append "text",200,1000
- rs.Open
-
- ts = fso.OpenTextFile("1.txt",1).ReadAll
-
- For Each line In reExecute(ts,".+")
- rs.AddNew
- rs("length") = Len(line)
- rs("text") = line
- rs.Update
- Next
-
- rs.Sort = "length DESC"
- rs.MoveFirst
-
- Do Until rs.EOF
- str = str & rs("text").value & vbCrLf
- rs.MoveNext
- Loop
-
- fso.CreateTextFile("2.txt",True).Write str
-
- Function reExecute(text,pattern)
- Set re = New RegExp
- re.Pattern = pattern
- re.Global = True
- re.MultiLine = True
-
- Set reExecute = re.Execute(text)
- End Function
复制代码
|