2

I have a comma-delimited list of email addresses with each actual address prepended by the contact's name (from Gmail). Here's an example:

Fred Flintstone <fred@flintstone.org>, Wilma Flintstone <wilma@flintstone.org>, Barney Rubble <barney@rubble.org>, Bamm-Bamm Rubble <bammbamm@rubble.org>,

converts to:

fred@flintstone.org, wilma@flintstone.org, barney@rubble.org, bammbamm@rubble.org,

Background info: I am trying to paste the list of contacts into a webex invite, which can only accept email addresses.

Remove everything except regex match in Vim is related, but all the email addresses are on one line in this case.

Community
  • 1
  • 1
paragbaxi
  • 3,965
  • 8
  • 44
  • 58

3 Answers3

4

Have you tried?

:s/.\{-}\%(\(,\s*\)\|<\(.\{-}\)>\)/\1\2/g

The following will also work:

:s/.*/\=join(map(split(submatch(0), ','), "matchstr(v:val, '<\\zs.*\\ze>')"), ', ')
Luc Hermitte
  • 31,979
  • 7
  • 69
  • 83
2

with awk

    echo "Fred Flintstone <fred@flintstone.org>, Wilma Flintstone <wilma@flintstone.org>, Barney Rubble <barney@rubble.org>, Bamm-Bamm Rubble <bammbamm@rubble.org>
"|awk -F'<|>' '{for (i=1;i<=NF;i++)printf (i%2==0)?$i",":""}'

or in VIM

:%s/,/\r/g
:%s/.*<\(.*\)>/\1/g
Kent
  • 189,393
  • 32
  • 233
  • 301
  • `%s/.*<\(.*\)>/\1/g` results in `Fred Flintstone Wilma Flintstone Barney Rubble Bamm-Bamm Rubble `. – paragbaxi Sep 16 '11 at 15:40
  • `:%s/.*<\(.*\)>/\1/g` results in `bammbamm@rubble.org` – paragbaxi Sep 16 '11 at 15:41
  • The idea behind Kent's vim code is to split the unique line into several lines, then keep only what's between the angle brackets on each line. Eventually, you'll have to merge all the lines generated into one at the end. – Luc Hermitte Sep 16 '11 at 16:02
  • Thanks Luc Hermitte. After running both lines, the email address are correctly extracted on separate lines. – paragbaxi Sep 16 '11 at 17:28
  • Luc, thanks for the explanation. "J" can be used to join lines. – Kent Sep 16 '11 at 23:48
-2

Could you not put it into Excel, then split the data on the comma and then and then do a find and replace to get rid of the angel bracket

Unless you are using some code to do it this would be the easiest unless you have 100,000's of thousand addresses

richard
  • 15
  • 3