perl 对txt 两个文件进行数值比对较复杂数据操作.求帮忙.
a.txt文件如下BJI-HBSC-6000-021,二电厂二期HG-BJM141,144,二电厂二期HG-BJM141-0,37240,21414,107.21234,...
a.txt文件如下
BJI-HBSC-6000-021,二电厂二期HG-BJM141,144,二电厂二期HG-BJM141-0,37240,21414,107.21234,34.50489,60,1,7,17,78_17,,,GSM900,78,23,59,69,,,,,,,,,20404,20405,21291,21293,21415,21416,22894,22895,22896,29418,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-007,国税局HD-BJD423,148,国税局HD-BJD423-2,37233,24233,107.13928,34.37154,320,1,7,17,578_17,,,DCS1800,578,529,546,566,568,570,572,629,,,,,20001,20004,20058,20402,20750,21431,24152,24161,24162,24163,24231,24232,24257,24258,24259,24263,24311,24312,24674,24744,24746,25651,25653,25667,25668,25669,25951,25953,26067,26068,27054,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-022,眉县槐牙镇北HG-BJM048,26,眉县槐牙镇北HG-BJM048-0,37356,20484,107.86918,34.20968,60,1,7,17,78_17,,,GSM900,78,3,9,51,66,,,,,,,,20334,20335,20336,20471,20472,20473,20485,20486,21961,21962,21963,21971,21972,21973,22027,22241,25004,25005,25006,28729,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-005,七零二厂区HG-BJ841,38,七零二厂区HG-BJ841-0,36914,28417,107.5779,34.32731,60,2,0,20,79_20,,,GSM900,79,31,33,39,45,64,,,,,,,20043,21253,21735,23581,23582,23583,23961,23962,23963,24561,24921,24922,24923,25431,25432,25433,25706,26597,27607,27608,27609,27617,27618,27619,28418,28419,29727,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-012,七十一信箱西HG-BJM475,205,七十一信箱西HG-BJM475-0,37236,24754,107.251306,34.30471,60,2,0,20,79_20,,,GSM900,79,53,67,71,,,,,,,,,21071,21072,21073,22671,23235,23246,23248,24755,24756,25677,25678,25679,25874,25875,25876,26332,26333,27447,27448,27449,28937,28938,28939,28948,28967,28968,,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-020,西谢村HG-BJM136,111,西谢村HG-BJM136-1,37246,21365,107.52003,34.36158,180,2,3,23,72_23,,,GSM900,72,42,63,,,,,,,,,,20014,20016,20161,20556,20642,20766,20767,21361,21363,21364,21781,21782,22949,23277,23278,23279,23927,24392,27225,29087,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
b.txt文件如下
西谢村HG-BJM136-1,78,7,1,17,78_17,,,,,,,77,19.91 ,285.33
西谢村HG-BJM136-1,79,0,2,20,79_20,,,,,,,438,23.97 ,1800.83
要求:
以上两个文件都是CSV文件.按照豆号分值,希望能够对这两个文件内的数据进行一些分析和转换.
1 首先针对B文件第一列这个名称,在A文件中寻找相同名称的行,将该行中的第7和8个数字记下比如.第7个数就叫jingdu,第8个数叫weidu.
2 然后在B文件中.每行取第7个数据,类似78_17这种,记下该数为B7.
3 在A文件中.找到第7个数和第8个数,记录下来分别叫A7,A8,然后找到每行第13位的数,记为A13,用B7与A13比较.假如一致,说明找到同样的行,就做一个运算,运算为(A7-jingdu)+(a8-weidu),把得到的这个数字记为juli,这种相同的行有好几行.所以求得的这个值就有好几个.
4 最后就对符合条件,进行计算后的各个类似行,按照juli这个值比大小.经过比较后,选择juli最小那个值的行.把这一行的第1列,第4列,第16到28列写到B.TXT比较的该行最后一列之后. 展开
BJI-HBSC-6000-021,二电厂二期HG-BJM141,144,二电厂二期HG-BJM141-0,37240,21414,107.21234,34.50489,60,1,7,17,78_17,,,GSM900,78,23,59,69,,,,,,,,,20404,20405,21291,21293,21415,21416,22894,22895,22896,29418,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-007,国税局HD-BJD423,148,国税局HD-BJD423-2,37233,24233,107.13928,34.37154,320,1,7,17,578_17,,,DCS1800,578,529,546,566,568,570,572,629,,,,,20001,20004,20058,20402,20750,21431,24152,24161,24162,24163,24231,24232,24257,24258,24259,24263,24311,24312,24674,24744,24746,25651,25653,25667,25668,25669,25951,25953,26067,26068,27054,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-022,眉县槐牙镇北HG-BJM048,26,眉县槐牙镇北HG-BJM048-0,37356,20484,107.86918,34.20968,60,1,7,17,78_17,,,GSM900,78,3,9,51,66,,,,,,,,20334,20335,20336,20471,20472,20473,20485,20486,21961,21962,21963,21971,21972,21973,22027,22241,25004,25005,25006,28729,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-005,七零二厂区HG-BJ841,38,七零二厂区HG-BJ841-0,36914,28417,107.5779,34.32731,60,2,0,20,79_20,,,GSM900,79,31,33,39,45,64,,,,,,,20043,21253,21735,23581,23582,23583,23961,23962,23963,24561,24921,24922,24923,25431,25432,25433,25706,26597,27607,27608,27609,27617,27618,27619,28418,28419,29727,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-012,七十一信箱西HG-BJM475,205,七十一信箱西HG-BJM475-0,37236,24754,107.251306,34.30471,60,2,0,20,79_20,,,GSM900,79,53,67,71,,,,,,,,,21071,21072,21073,22671,23235,23246,23248,24755,24756,25677,25678,25679,25874,25875,25876,26332,26333,27447,27448,27449,28937,28938,28939,28948,28967,28968,,,,,,,,,,,,,,,,,,,,,,,
BJI-HBSC-6000-020,西谢村HG-BJM136,111,西谢村HG-BJM136-1,37246,21365,107.52003,34.36158,180,2,3,23,72_23,,,GSM900,72,42,63,,,,,,,,,,20014,20016,20161,20556,20642,20766,20767,21361,21363,21364,21781,21782,22949,23277,23278,23279,23927,24392,27225,29087,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
b.txt文件如下
西谢村HG-BJM136-1,78,7,1,17,78_17,,,,,,,77,19.91 ,285.33
西谢村HG-BJM136-1,79,0,2,20,79_20,,,,,,,438,23.97 ,1800.83
要求:
以上两个文件都是CSV文件.按照豆号分值,希望能够对这两个文件内的数据进行一些分析和转换.
1 首先针对B文件第一列这个名称,在A文件中寻找相同名称的行,将该行中的第7和8个数字记下比如.第7个数就叫jingdu,第8个数叫weidu.
2 然后在B文件中.每行取第7个数据,类似78_17这种,记下该数为B7.
3 在A文件中.找到第7个数和第8个数,记录下来分别叫A7,A8,然后找到每行第13位的数,记为A13,用B7与A13比较.假如一致,说明找到同样的行,就做一个运算,运算为(A7-jingdu)+(a8-weidu),把得到的这个数字记为juli,这种相同的行有好几行.所以求得的这个值就有好几个.
4 最后就对符合条件,进行计算后的各个类似行,按照juli这个值比大小.经过比较后,选择juli最小那个值的行.把这一行的第1列,第4列,第16到28列写到B.TXT比较的该行最后一列之后. 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询