extract e-mail addresses from body of etxt file

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
albert lee

extract e-mail addresses from body of etxt file

Post by albert lee »

Hi, is there a way to use TextPad to extract e-mail addresses
from the body of a plain text file?
User avatar
skaemper
Posts: 51
Joined: Mon Mar 03, 2003 1:07 pm
Location: (Northern) Germany
Contact:

Re: extract e-mail addresses from body of etxt file

Post by skaemper »

albert lee wrote:Hi, is there a way to use TextPad to extract e-mail addresses from the body of a plain text file?
Albert,

while you might find (some) email addresses by an approach like this

Code: Select all

\<[-a-zA-Z0-9_\.]+@\([-a-zA-Z0-9_]+.\)+
I know of no way to extract the emails from a file (and insert them soewhere else). But you can extract the lines containing the addresses and copy them by using the "Mark all" button from the find dialog box.
Then use
  • Edit | Copy other | Bookmarked lines
to copy these lines.

Note however that matching email addresses (with regular expressions) is quite a complex theme in itself:
Jeffrey Friedls excellent book "Mastering Regular Expressions" contains a working example which is more than 4k characters long...
Here's the link :arrow: 1st Edition of Mastering Regular Expressions :!:
And here's the link to the 2nd edition (although I don't know whether the email address is in there, too.)

Personally I'd use a small Ruby :D script for things like that, not only because programming Ruby :D or just mentioning Ruby :D makes me smile.

Hope that helped.

Stephan
"It's POLYMORPHIC!"
A former colleague
albert lee

Re: extract e-mail addresses from body of text file

Post by albert lee »

I know of no way to extract the emails from a file (and insert them soewhere else). But you can extract the lines containing the addresses and copy them by using the "Mark all" button from the find dialog box... ...
Thanks for your inputs, Stephan. Happy Rubying!

-albert-
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

This is another candidate to make a TextPad Macro to do this for you.

These are the steps to follow to make the macro:

Assume the following email format:

From: Somebody@myplace.com
Date: Tue, 10 Dec 2002 18:23:53 EST
Subject:This is a test
To: myname@home.com
=============================
TextPad Macro steps:

A. Open the destination document to receive the email address.
B. Open the email text document and make sure the cursor is above the FROM: field
C. Start Recording macro. Record the macro using the following steps:

1. Move cursor to top of document. (CTL-HOME)
2. Find "From:" (F5, Conditions=Text, Direction=Down, Find Next)
3. Right arrow 2 times
4. Highlight From address (Shift End)
5. Copy to Clipboard (CTL-C)
6. Switch window to destination document to receive email address
7. Move cursor to desired location to receive email address
8. Paste from clipboard (CTL-V)

Stop recording macro and save it.
D. Add the macro to your macro list using Configure, Preferences, Macros.
E. Now you can use the macro on a document. Just make sure that there is no earlier "From:" on the document. Click on Macros, and select from the list.

Note: Try to use commands, shortcut keys, etc. to locate the cursor in the destination document. Use things like CTL-END, Goto Line x, Goto Bookmark etc. That will ensure the same results every time you run the macro. Do all of the steps manually and make notes of your steps before you record the macro. IT CANNOT BE EDITED!

CAUTION! Macros cannot be edited, so it is important to be sure all your steps will be correct and work under all conditions. You will need to make separate identical macros to do one time, or do through the selected area, or do to the end of your document. It may be advisable to select 'run once" to give a little control.

But try the macro approach. When done correctly they are very effective......Good luck....
Hope this was helpful.............good luck,
Bob
albert lee

Re: Bob Hansen's take on extracting email addresses

Post by albert lee »

Thanks for your detailed tip, Bob.

It sure would work for e-mail messages saved as text file.

I was thinking more expansively of text files other than saved messages in which there are multiple and unpredictable occurrences of e-mail addresses sprinkled throughout the body that someone may want to harvest.

Would this mean a macro able to search first for the "@" character and then move to the very first character of the string containing that @ and then start highlighting until the end of the contiguous string, then copying the highlighted string and then pasting the string to a destination at a separately opened Textpad file. Or something that went like that?

Thanks again.

-albert-
User avatar
Bob Hansen
Posts: 1517
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

You got the idea:
Or something that went like that?
No one can answer that but you. It depends on the content of the document you are looking at. If there are never an other instances of "@" you may be OK. If the line continues and wraps you will have to allow for that. If desired address witll always start with "From:", you could search for that vs. "@", but again, will there ever be any other instances of "From:" that don't apply.

What I am suggesting to you is the power of TextPad macros to do many tasks, but the details need to be thought properly. For instantce, to prepare to use the macro we have discussed, there could be earlier steps in the macro to search for every "From:" and insert a line ending before it. That will make every "From:" start on the beginning of a line. You may also want to macro to tun of line wrapping before it starts.

A good practice with the macros is to always start with CTL-HOME, set up the environments from the Menu Bar that will be different from your defaults,, then proceed.

You will have to play with this, make some short macros and see what you can do, and how you have to plan the keystrokes. Again, you cannot edit or single step the macros, they just run.

So I would suggest you open a second document when doing the macro manually. Write down each step, each keystroke to accomplish the step, example did you hit the END key or did you hit the RIGHT arrow 15 times? It will make a difference when the macro runs. After documenting your steps, record the macro. Watch the results. If wrong, stop recording, change your notes about the steps to take, and start recording again. First few times may be frustrating, but soon you will get a feel of what keystrokes to use. Again I would suggest using built in navigation tools vs. using spaces, arrows, etc. But that can't always happen.

Good luck with your macros.....
Hope this was helpful.............good luck,
Bob
Post Reply