I want to achieve this specific task, I have 2 files, the first one with emails and credentials:
xavier.desprez@william.com:Xavier
xavier.locqueneux@william.com:vocojydu
xaviere.chevry@pepe.com:voluzigy
Xavier.Therin@william.com:Pussycat5
xiomara.rivera@william.com:xrhj1971
xiomara.rivera@william-honduras.william.com:xrhj1971
and the second one, with emails and location:
xavier.desprez@william.com:BOSNIA
xaviere.chevry@pepe.com:ROMANIA
I want that, whenever the email from the first file is found on the second file, the row is substituted by EMAIL:CREDENTIAL:LOCATION , and when it is not found, it ends up being: EMAIL:CREDENTIAL:BLANK
so the final file must be like this:
xavier.desprez@william.com:Xavier:BOSNIA
xavier.locqueneux@william.com:vocojydu:BLANK
xaviere.chevry@pepe.com:voluzigy:ROMANIA
Xavier.Therin@william.com:Pussycat5:BLANK
xiomara.rivera@william.com:xrhj1971:BLANK
xiomara.rivera@william-honduras.william.com:xrhj1971:BLANK
I have do several tries in python, but it is not even worth it to write it because I am not really close to the solution.
Regards !
EDIT:
This is what I tried:
import os
import sys
with open("test.txt", "r") as a_file:
for line_a in a_file:
stripped_email_a = line_a.strip().split(':')[0]
with open("location.txt", "r") as b_file:
for line_b in b_file:
stripped_email_b = line_b.strip().split(':')[0]
location = line_b.strip().split(':')[1]
if stripped_email_a == stripped_email_b:
a = line_a + ":" + location
print(a.replace("\n",""))
else:
b = line_a + ":BLANK"
print (b.replace("\n",""))
This is the result I get:
xavier.desprez@william.com:Xavier:BOSNIA
xavier.desprez@william.com:Xavier:BLANK
xaviere.chevry@pepe.com:voluzigy:BLANK
xaviere.chevry@pepe.com:voluzigy:ROMANIA
xavier.locqueneux@william.com:vocojydu:BLANK
xavier.locqueneux@william.com:vocojydu:BLANK
Xavier.Therin@william.com:Pussycat5:BLANK
Xavier.Therin@william.com:Pussycat5:BLANK
xiomara.rivera@william.com:xrhj1971:BLANK
xiomara.rivera@william.com:xrhj1971:BLANK
xiomara.rivera@william-honduras.william.com:xrhj1971:BLANK
xiomara.rivera@william-honduras.william.com:xrhj1971:BLANK
I am very close but I get duplicates ;)
Regards