I have a two file. I tried merge two file.
But my script some issue. my English is not good. sorry.
please compare result. with elif eachkey not in ali1: without elif eachkey not in ali1:
without elif eachkey not in ali1: running result has only correct data. But with elif eachkey not in ali1: running result has running progress data.
I want remove progress data.
match alias1 in a.txt to aliases in b.txt, result is Zone,alias1,Port,WWN,alias2 not match alias1 in a.txt to aliases in b.txt, result is Zone,alias1,N/A,N/A,alias2
a.txt file has below data.
Zone,Alias1,Alias2
VNX7600SPB3_8B3_H1,VNX7600SPB3,8B3_H1
VNX7600SPBA_8B4_H1,VNX7600SPA3,8B4_H1
CX480SPA1_11B3_H1,CX480SPA1,11B3_H1
CX480SPB1_11B4_H1,CX480SPB1,11B4_H1
b.txt file has below data.
WWN,Port,Aliase
xx:06:01:vv:08:60:vv:78,35,VNX7600SPA3
vv:06:01:xx:08:60:xx:78,39,VNX7600SPB3
My result is below. my result has elif eachkey not in ali1: progress data.
VNX7600SPB3_8B3_H1;VNX7600SPB3;39;vv:06:01:xx:08:60:xx:78;8B3_H1;1
VNX7600SPB3_8B3_H1;VNX7600SPB3;N/A;8B3_H1;
VNX7600SPBA_8B4_H1;VNX7600SPA3;N/A;8B4_H1; <- `elif eachkey not in ali1:` made data. I don't need because 'if eachkey in ali1:' work.
VNX7600SPBA_8B4_H1;VNX7600SPA3;35;xx:06:01:vv:08:60:vv:78;8B4_H1;2
CX480SPA1_11B3_H1;CX480SPA1;N/A;11B3_H1;
CX480SPA1_11B3_H1;CX480SPA1;N/A;11B3_H1;
CX480SPB1_11B4_H1;CX480SPB1;N/A;11B4_H1;
CX480SPB1_11B4_H1;CX480SPB1;N/A;11B4_H1;
I want see below result
VNX7600SPB3_8B3_H1;VNX7600SPB3;39;vv:06:01:xx:08:60:xx:78;8B3_H1;1
VNX7600SPBA_8B4_H1;VNX7600SPA3;35;xx:06:01:vv:08:60:vv:78;8B4_H1;2
CX480SPA1_11B3_H1;CX480SPA1;N/A;11B3_H1;
CX480SPB1_11B4_H1;CX480SPB1;N/A;11B4_H1;
Below is my script. my script make no need line because for. Who can solved this issue?
f = open('b.txt', 'r')
dict = {}
next(f)
i=0
for line in f:
i += 1
line = line.split(',')
line = (line[2].replace('\n','') +',' + line[1] + ";" + line[0]).strip()
if line.startswith(",") == 1:
line = str("Blank") + str(i) + line
else:
line = line
k, v = line.strip().split(',')
dict[k.strip()] = v.strip()
f.close()
f = open('a.txt','r')
next(f)
with open('result.txt','w') as s:
for lines in f.xreadlines():
lines = lines.split(',')
zone = lines[0]
ali1 = lines[1]
ali2 = lines[2].replace('\n','')
##I think below line make same line and no need line
for eachkey in dict.keys():
if eachkey in ali1:
result = zone + ";" + ali1 + ";" + dict[eachkey] + ";" + ali2 + ";"
elif eachkey not in ali1:
result = zone + ";" + ali1 + ";" + "N/A" + ";" + ali2 + ";"
s.write(result + '\n')
s.close()
Aucun commentaire:
Enregistrer un commentaire