Using the shell to transform an Exchange email list…

Recently, I needed to create a one-address-per-line email address list, using only an existing Exchange group mailbox as input.

First we start in Windows…

I opened Outlook and prepared to create a new email and typed in the email group.  Once shown, I clicked the “plus” (+) symbol next to the group to expand it.  Swipe across the list, and do a CTRL+C to copy them to the clipboard.

Now, to Linux…

Shell into a Linux box, and paste the clipboard contents into a file (for instance, input.txt).  The input format will look a bit like this:

Jeremy Pavlov <>; Other Guy <>

…and so on…

Now run the following command against your input file:

cat input.txt |tr ";" "\n" |awk '{ print $3 }' | sed s/"<"//g |sed s/">"//g

And you should end up with an output.txt that looks like this:

…and so on.

This format is now perfect for use in various places, like… oh… for instance… the Subscribe2 plugin in WordPress… …Which is exactly where I use it to keep my internal subscriber list up-to-date.




Update: For a comma-delimited list, use this:

cat input.txt |tr ";" "\n"|awk '{ print $3 }'| sed s/"<"//g |sed s/">"//g|tr "\n" ","

1 Comment

  1. Jeremy Pavlov

    …or, if you want it to be just a comma-separated list, you can used this instead:

    cat input.txt |tr “;” “\n”|awk ‘{ print $3 }’|sed s/””//g|tr “\n” “,”

Leave a Comment

Your email address will not be published. Required fields are marked *