There are 2 txt files, the first login-pass.txt is:

login1,password1 login2,password2 login3,password3 

The second list.txt is:

 login1 login2 login3 

In the login-pass.txt file, you need to search for lines from the list.txt file and, if they match, write to another file in the format:

 login,password 

Found a similar script here

 with open('/root/login-pass.txt') as f: haystack = f.read() if not haystack: sys.exit("Could not read haystack data :-(") with open('/root/list.txt') as f: for needle in (line.strip() for line in f): if needle in haystack: print(needle, 'FOUND!!!') 

But if it matches, it writes only a line from the list. only logins (more precisely, not even the script writes, but I launch it with output to a file, in general, this item suits me), please help to add / rewrite so that it writes the value from the login-pass.txt list

    2 answers 2

    Read the login-pass.txt and fill the dictionary in pairs (login, pass), splitting the line with them using split

    Search in this dictionary; when you find it, give out both the search key and the value

       with open('/root/list.txt') as f: sf = set(f) with open('/root/login-pass.txt') as f: up = [s for s in f if any(map(s.startswith, sf))] with open('/root/result.txt', 'w') as f: f.writelines(up)