Remove everything except characters between '<' & '>,' in Vim — extract email addresses from Gmail “To” field

StackOverflow https://stackoverflow.com/questions/7446716

문제

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.

도움이 되었습니까?

해결책

Have you tried?

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

The following will also work:

:s/.*/\=join(map(split(submatch(0), ','), "matchstr(v:val, '<\\zs.*\\ze>')"), ', ')

다른 팁

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

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top