Monday, 7 March 2011

Extract email addresses

Grep is a great search tool in Ubuntu/Linux thats also available for Windows.

A friend lost their email contacts because of a hotmail hack... So I downloaded all emails they had sent to me and then used grep to create a list of email addresses. Heres how I did it:
  1. Create a label (friendsname) in Google mail for all email received from friendsemail@hotmail.co.uk
  2. Install Thunderbird and connect to my Google mail account using IMAP.
  3. Thunderbird creates a folder for each label, so go to the folder for friendsname
  4. Highlight all of the emails and select file -> save as -> folder name - this will save each email as a file in a folder (friendsfolder)
  5. Open a linux terminal or windows command prompt.
  6. Change directory to the folder in step 4 above (eg in Ubuntu: cd Documents/friendsfolder)
  7. Then enter grep -Eiorh '([[:alnum:]_.]+@[[:alnum:]_]+?\.[[:alpha:].]{2,6})' "./" | sort | uniq > emails.txt
  8. This will copy all email addresses into a file called emails.txt
You can then open the file with a text editor, delete any emails you don't want and import into your email account.

1 comment:

  1. Excellent, clearly described solution. Thank you very much.

    ReplyDelete