Terminal: Convert file contents (emails) to MD5

Discussion in 'Mac Programming' started by jobetter23, Nov 17, 2010.

  1. jobetter23 macrumors newbie

    Nov 17, 2010
    Hey guys, anybody know, via terminal, how to convert a file with many lines of e-mails into an md5 file and export it ito .txt file- if possible , not to delete the e-mails.
    ex :
    jojo@aol.com into

    Jojo@aol.com, 60b4498f429ea861dhja7807ae69ec4a

    any help will be great! :rolleyes:
  2. mfram macrumors 65816

    Jan 23, 2010
    San Diego, CA USA
    What's the goal of what you are trying to accomplish? MD5 is a hashing algorithm. It's designed to show that the contents of two files are the same. So if you hash a file, it would have nothing do with deleting it. MD5 is not encryption.
  3. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    $ [B]md5 -s jojo@aol.com[/B]
    MD5 ("jojo@aol.com") = 8f6267dd59127998be428284e7ebee1e
    Wrap that in a for loop and you're most of the way to what I think you want.

  4. Zazoh macrumors 6502a


    Jan 4, 2009
    San Antonio, Texas
    You will need to loop and find a pattern. For example XXXXXXX@xxxxx.xxxxx where the xxxxs can be anything. I recently did this in JavaScript using the match method. Not sure it's equivalent in c or other scripting Lang.
  5. jobetter23 thread starter macrumors newbie

    Nov 17, 2010
    Ill try to make my goal more clear, sorry guys

    This is my goal: somebody sends me a file of md5 encrypted e-mails. So i need to turn my own list of normal e-mails into MD5 so i can compare it with that md5 list that they send me.

    So i want to input my entire list of regular e-mails (thousands of lines) and input it into terminal and have it return a new file of md5 names.

    If there is an easier way to do this let me know
    Thanks so much!!
  6. cqexbesd macrumors regular

    Jun 4, 2009
    perl -MDigest::MD5 -n -E 'chomp($_); say(join(", ", $_, Digest::MD5::md5_hex($_)))'
    Feed it the data on stdin, get the output on stdout.

  7. ulbador macrumors 68000


    Feb 11, 2010
    Ahh, this is where Perl truly shines...
  8. jobetter23 thread starter macrumors newbie

    Nov 17, 2010
    Sorry just a little new to this - where exactly am i supposed to insert the file (and the output), if u can tell me where exactly in the code.
  9. subsonix macrumors 68040

    Feb 2, 2008
    There are also alternative ways to do this in bash, (to expand on what balamw was suggesting).

    while read line; do md5 -s "$line" ; done < emails.txt
    This will take a text file with emails and dump the md5 checksums to stdout. You can also redirect the output to a new file if you want to.
  10. jobetter23 thread starter macrumors newbie

    Nov 17, 2010
  11. jobetter23 thread starter macrumors newbie

    Nov 17, 2010
    Is there a way to add a line break in this code so that he first line of the stdout is a blank line?

Share This Page