1

I have a large file A (consisting of emails), one line for each mail. I also have another file B that contains another set of mails but in MD5.

Which command would I use to remove all the addresses that exist in md5 file B from the file A.

So, if file A contained:

A

B

C

and file B contained:

9d5ed678fe57bcca610140957afab571

f623e75af30e62bbd73d6df5b50bb7b5

3a3ea00cfc35332cedf6e5e9a32e94da

( those are letters B D E , but in MD5 )

Then file A should be left with:

A

C

Any help would be much appreciated! Somebody will surely come up and help me

0

Here's a little Python script that will do that:

#!/usr/bin/env python
import sys
import hashlib

with open(sys.argv[2]) as hashfile:
    hashes = set(hashfile.read().splitlines())

with open(sys.argv[1]) as emailfile:
    for email in emailfile:
        email = email.rstrip('\n')
        md5 = hashlib.md5()
        md5.update(email)
        if md5.hexdigest() not in hashes:
            print email

Pass it the names of your files as arguments (e.g., python whatever_name_you_save_it_as.py file_A file_B), and it will print the output you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.