lundi 11 janvier 2021

searching a specific values from one file in another file using nested for loop

I have two files, file A.txt has hundreds of rows of format (ip,mac) and file B.txt has hundreds of rows of format (mac). what I am looking for is to search the (macs) from file B in file A and if found to print the line (ip, mac) from file A. there are already more than 100 mac matches between the two files but with the code I wrote it returns only the first match.

below is my simple code

with open("B.txt", "r") as out_mac_file, open("A.txt", "r") as out_arp_file:
    for x in out_mac_file:
        for y in out_arp_file:
            if x in y:
                print(y)

Any idea what could be wrong in the code, or if there other ways to do that?

Edit: Adding the format of file A and file B

File B

64167f18cd3d
64167f18c77a
64167f067082
64167f0670b5
64167f067400
64167f0674e5
64167f06740d

File A

10.55.14.160,64167f869f18
10.55.20.59,64167f37a5f4
10.55.20.62,64167f8866e0
10.55.20.65,64167f8b4bd8
10.55.20.66,64167f372a72
10.55.20.67,64167f371436

Aucun commentaire:

Enregistrer un commentaire