Using grep for organizing emails

9 views
Skip to first unread message

maciek.schejbal

unread,
Jan 15, 2010, 1:36:15 PM1/15/10
to BBEdit Talk
Hi,

I have a list of emails enclosed within <> signs preceded by a name,
usually in two or three word format. I need to extract those emails
and place them in a comma-delimited document.

Each entry is on a separate line, followed by the carriage return
though I'm curious how to perform that extraction without separate
lines present.

Thanks for your help,
Maciek

Kendall Conrad

unread,
Jan 15, 2010, 8:30:51 PM1/15/10
to BBEdit Talk
It would be helpful to see an example of what you're working with.
I'll assume it looks something like this,

john <sm...@email.com>
jan <d...@other.com>

Grep: ^([^<]+)<([^>]+)>$
Replace with: \1,\2

That gets pretty close depending on the exact format you have to work
from, and I'm also not sure what you want to end result to look like.
If you could provide examples I could give a more precise solution.

~angelwatt

On Jan 15, 1:36 pm, "maciek.schejbal" <maciek.schej...@gmail.com>
wrote:

maciek.schejbal

unread,
Jan 17, 2010, 12:19:36 AM1/17/10
to BBEdit Talk
Hi Kendall,

here is the concrete example. I want to turn:

ann lkjlkjlkj <tlkj...@msn.com>
Nlkjlkj Teilkjea <nlk...@gmail.com>
"who...@me.com" <who...@me.com>
"Mr. Cashman" <ca...@mac.com>

into:
tlkj...@msn.com, nlk...@gmail.com, who...@me.com, ca...@mac.com

and into:

tlkj...@msn.com
nlk...@gmail.com
who...@me.com
ca...@mac.com

Many thanks,
Maciek

maciek.schejbal

unread,
Jan 17, 2010, 12:25:24 AM1/17/10
to BBEdit Talk
Not sure my reply went through so I'm resending with better examples.

Kendall, I would like these lines:

Joel lkj <joe...@gmail.com>
"lkj...@gmail.com" <lkj...@gmail.com>
<l...@aol.com>
"Mr.Gilbert Llkjlkj" <lkj...@fasny.org>

to appear like this:

joe...@gmail.com, lkj...@gmail.com, l...@aol.com, lkj...@fasny.org

and afterwards like this:

joe...@gmail.com
lkj...@gmail.com
l...@aol.com
lkj...@fasny.org

Many thanks,
Maciek


On Jan 15, 8:30 pm, Kendall Conrad <angelw...@gmail.com> wrote:

Kendall Conrad

unread,
Jan 17, 2010, 12:24:41 PM1/17/10
to BBEdit Talk
OK, my original idea should work pretty well for the second format
that you want, just change the replace with to \2. For the comma-
separated addresses on a single line use,

([^<]+)<([^>]+)>\r

for the regex, then

\2,

for the replace with. You'll of course need to delete the last command
from the result. That at least worked for me.

-Kendall

On Jan 17, 12:25 am, "maciek.schejbal" <maciek.schej...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages