Home > English, Techie > Quick Perl Regexp in VIM to format e-mails list

Quick Perl Regexp in VIM to format e-mails list

I have a list of e-mails that I extracted from MySQL as something like this:

name@example.com firstname lastname

name2@example.com firstname2 lastname2

name3@example.com firstname3 lastname3

and I want them to be in this format:

firstname lastname <name@example.com>

firsntame2 lastname2 <name2@example.com>

firstname3 lastname3 <name3@example.com>

Using VIM, I can do:

:% s/^/</

:% s/\s/> /

:% s/\(<.*>\)\s\(\w*\)\s\(.*$\)/\2 \3 \1/

The last one is a bit more complex but uses the \n-style references to parenthesed elements in the matching part.

Advertisements
Categories: English, Techie Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: