Terminal: Convert file contents (emails) to MD5

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

  1. macrumors newbie

    Joined:
    Nov 17, 2010
    #1
    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. macrumors 6502a

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #3
    Code:
    $ [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.

    B
     
  4. macrumors 6502

    Zazoh

    Joined:
    Jan 4, 2009
    Location:
    Mico, Texas
    #4
    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. thread starter macrumors newbie

    Joined:
    Nov 17, 2010
    #5
    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. macrumors member

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

    Andrew
     
  7. macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #7
    Ahh, this is where Perl truly shines...
     
  8. thread starter macrumors newbie

    Joined:
    Nov 17, 2010
    #8
    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.
    Thanks!!
     
  9. macrumors 68040

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

    Code:
    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. thread starter macrumors newbie

    Joined:
    Nov 17, 2010
    #10
    Thanks ! Both work great!! magic!
     
  11. thread starter macrumors newbie

    Joined:
    Nov 17, 2010
    #11
    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