本帖最后由 happy886rr 于 2017-7-5 19:03 编辑
batch- @echo off
-
- REM 建立索引
- for /f "tokens=2*" %%a in (1.txt) do (
- set "__%%a=%%b"
- )
-
- REM 文本排序
- for /f "tokens=1,2" %%a in (2.txt) do (
- call,set "__#%%b=%%a %%b %%__%%b%%"
- )
-
-
- REM 写入文件
- (
- REM 文本排序
- for /f "tokens=2 delims==" %%a in ('set __#') do (
- echo %%a
- )
- )>3.txt
-
- REM 打开结果
- start 3.txt
- exit /b
复制代码 python- # 2017-07-05 by LEO
-
- def PText():
- # 建立字典
- myINDEX={}
- myTEXT=[]
-
- # 读取索引
- for rLINE in open("1.txt"):
- rDIC=rLINE.split()
- myINDEX[rDIC[1]]=rDIC[2]
-
- # 遍历对象
- for rLINE in open("2.txt"):
- rDIC=rLINE.split()
- # 在字典中查找KEY
- if rDIC[1] in myINDEX:
- # 拼接文本
- myTEXT.append(rDIC[0] +" "+ rDIC[1] +" "+ myINDEX[rDIC[1]] +"\r\n")
-
- # 排序
- myTEXT.sort()
-
- # 输出文件
- with open('3.txt', 'w') as f:
- for oLINE in myTEXT:
- f.write(oLINE)
-
- # 主本
- if __name__ =="__main__":
- PText()
复制代码 js- 1>1/* :
- @echo off
- cscript -nologo -e:jscript "%~f0" %*
- pause&exit /b
- */
-
- var myText=[], myIndex=readFile("1.txt");
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var f = fso.OpenTextFile("2.txt", 1);
-
- while (!f.AtEndOfStream){
- var s=[];
- s = f.ReadLine().split(/[ ]+/);
- if(myIndex[s[1]]){
- myText.push(s[0] +" "+ s[1] +" "+ myIndex[s[1]] + "\r\n");
- }
- }
- f.Close();
-
- myText.sort();
-
- var fText="";
- for(var i=0; myText[i]; i++){
- fText += myText[i];
- }
-
- fso = new ActiveXObject("Scripting.FileSystemObject");
- f = fso.OpenTextFile("3.txt", 2, true);
- f.WriteLine(fText);
- f.Close();
-
-
- //读文件
- function readFile(filename, myIndex){
- var fso = new ActiveXObject("Scripting.FileSystemObject");
- var f = fso.OpenTextFile(filename, 1);
- var myIndex=[];
- while (!f.AtEndOfStream){
- var s=[];
- s = f.ReadLine().split(/[ ]+/);
- myIndex[s[1]]=s[2];
- }
- f.Close();
- return myIndex;
- }
复制代码
|