I have 2 files:
srv_to_snap.csv
which lists servers each line like:
srv1
srv2
rhev_srv_list_with_id.csv
which has a list of servers with its ID each line like:
('srv1', '67876232-doiud987-834')
('srv2', '67876232-doiud9oo-123')
('srv3', '67876232-doi989oo-783')
I am trying to search the server name one by one from srv_to_snap.csv
in rhev_srv_list_with_id.csv
line by line and if a match is found, it will return only the id of the server.
I have tried the below code..
with open('srv_to_snap.csv', 'r') as srv_list:
for vm_name in srv_list:
with open('rhev_srv_list_with_id.csv', 'rb') as f:
for line in f:
if vm_name in line:
vm_id_tmp1 = str(line.split(" ")[1])
vm_id = str(vm_id_tmp1.split("'")[1])
print vm_id
This is not working as assignments can't be used in conditional statements. How do I work around this to get the IDs of all the vm_id
's listed in srv_to_snap.csv
?
I have tried re.search
as well but it also didnt print the IDs... Requesting anyone to help me what I am missing here.