我正在寻找一些帮助循环遍历我的文本文件中的每个组并将三个变量与我的 csv 匹配,并且在成功匹配时,它将向 csv 文件写入一些新变量:
在文本文件第 1 行匹配到 csv 元素 1 在文本文件第 2 行匹配到 csv 元素 0
每个学生将分为三个部分:
3
Tommy
144512/23332
第 1 部分和第 3 部分将分别写入元素 12 和 13。第 2 部分将用于第三次匹配,与 csv 元素 8 匹配,这是为了找出要写入的行。
“data”将被写入元素 14(第 15 列) “misc3”将被写入元素 15(第 16 列) “bla3”将被写入元素 16(第 17 列)
评论文本文件:
Textfile Item 1 (Will loop/cycle/run 4 times, because there are 4 students)
|
v
MData (N/A) <-- Match Line 1 (matches to csv element 1)
DMATCH1 <-- Match Line 2 (matches to csv element 0)
3 Tommy 144512/23332 <-- Match Line 3 (matches to csv element 8) (Loop 1)
1 Jim 90000/222311 <-- Match Line 3 (matches to csv element 8) (Loop 2)
1 Elz M 90000/222311 <-- Match Line 3 (matches to csv element 8) (Loop 3)
1 Ben 90000/222311 <-- Match Line 3 (matches to csv element 8) (Loop 4)
Data $50.90 <-- If "Data" Exists then filewrite to csv element 14 (Loop 1)
misc2 $10.40 <-- If "misc2" Exists then filewrite to csv element 15 (Loop 1)
bla3 $20.20 <-- If "bla3" Exists then filewrite to csv element 16 (Loop 1)
Textfile Item 2 (Will loop/cycle/run 2 times, because there are 3 students)
|
v
MData (B/B) <-- Match Line 1 (matches to csv element 1)
DMATCH2 <-- Match Line 2 (matches to csv element 0)
4 James Smith 2333/114441 <-- Match Line 3 (matches to csv element 8) (Loop 1)
4 Mike 90000/222311 <-- Match Line 3 (matches to csv element 8) (Loop 2)
4 Jessica Long 2333/114441 <-- Match Line 3 (matches to csv element 8) (Loop 3)
Data $50.90 <-- If "Data" Exists then filewrite to csv element 14 (Loop 1)
bla3 $5.44 <-- If "bla3" Exists then filewrite to csv element 16 (Loop 1)
Textfile Item 3 (Will loop/cycle/run 2 times, because there are 2 students)
|
v
Mdata <-- Match Line 1 (matches to csv element 1)
DMATCH3 <-- Match Line 2 (matches to csv element 0)
5 Joe Reane 0/0 <-- Match Line 3 (matches to csv element 8) (Loop 1)
5 Peter Jones 90000/222311 <-- Match Line 3 (matches to csv element 8) (Loop 2)
misc2 $420.00 <-- If "misc2" Exists then filewrite to csv element 15 (Loop 1)
bla3 $210.00 <-- If "bla3" Exists then filewrite to csv element 16 (Loop 1)
未注释的真实文本文件:
MData (N/A)
DMATCH1
3 Tommy 144512/23332
1 Jim 90000/222311
1 Elz M 90000/222311
1 Ben 90000/222311
Data $50.90
misc2 $10.40
bla3 $20.20
MData (B/B)
DMATCH2
4 James Smith 2333/114441
4 Mike 90000/222311
4 Jessica Long 2333/114441
Data $50.90
bla3 $5.44
Mdata
DMATCH3
5 Joe Reane 0/0
5 Peter Jones 90000/222311
Data $10.91
misc2 $420.00
bla3 $210.00
CSV 之前:
MATCH1,MATCH2,TITLE,TITLE,TITLE,TITLE,TITLE,TITLE,MATCH3,DATA,TITLE,TITLE
DMATCH1,MData (N/A),data,data,data,data,data,data,Tommy,55,data,data
DMATCH1,MData (N/A),data,data,data,data,data,data,Ben,54,data,data
DMATCH1,MData (N/A),data,data,data,data,data,data,Jim,52,data,data
DMATCH1,MData (N/A),data,data,data,data,data,data,Elz M,22,data,data
DMATCH2,MData (B/B),data,data,data,data,data,data,James Smith,15,data,data
DMATCH2,MData (B/B),data,data,data,data,data,data,Jessica Long,224,data,data
DMATCH2,MData (B/B),data,data,data,data,data,data,Mike,62,data,data
DMATCH3,Mdata,data,data,data,data,data,data,Joe Reane,66,data,data
DMATCH3,Mdata,data,data,data,data,data,data,Peter Jones,256,data,data
DMATCH3,Mdata,data,data,data,data,data,data,Lesley Lope,5226,data,data
CSV 之后:
MATCH1,MATCH2,TITLE,TITLE,TITLE,TITLE,TITLE,TITLE,MATCH3,DATA,TITLE,TITLE,,,,,
DMATCH1,MData (N/A),data,data,data,data,data,data,Tommy,55,data,data,3,144512/23332,Data $50.90,misc2 $10.40,bla3 $20.20
DMATCH1,MData (N/A),data,data,data,data,data,data,Ben,54,data,data,1,90000/222311,,,
DMATCH1,MData (N/A),data,data,data,data,data,data,Jim,52,data,data,1,90000/222311,,,
DMATCH1,MData (N/A),data,data,data,data,data,data,Elz M,22,data,data,1,90000/222311,,,
DMATCH2,MData (B/B),data,data,data,data,data,data,James Smith,15,data,data,4,2333/114441,Data $50.90,,bla3 $5.44
DMATCH2,MData (B/B),data,data,data,data,data,data,Jessica Long,224,data,data,4,2333/114441,,,
DMATCH2,MData (B/B),data,data,data,data,data,data,Mike,62,data,data,4,90000/222311,,,
DMATCH3,Mdata,data,data,data,data,data,data,Joe Reane,66,data,data,5,0/0,,misc2 $420.00,bla3 $210.00
DMATCH3,Mdata,data,data,data,data,data,data,Peter Jones,256,data,data,5,90000/222311,,,
DMATCH3,Mdata,data,data,data,data,data,data,Lesley Lope,5226,data,data,,,,,
有谁知道如何实现这一目标?
任何帮助将不胜感激!