Contact iFingers

Finger Tips - a fistful of handy web notes

Saturday, July 16, 2005

Grep Grep Hooray

I had the unenviable task of formatting 25000 email addresses for Mojo London's newsletter. First of all we had to export them from our Filemaker Pro database. Which was quite straightforward, but before we could import them into our newsletter tool, they needed a little tidying up.

Step 1. Remove empty lines

I opened the csv list in BBEdit and used this simple Grep Replace pattern to remove any blank lines.

Grep Replace BBEdit

This search patten, basically finds any carriage returns that start at the beginning of a line. The ^ character means at the the start of the line. The \r command is the carriage return character. Click on Replace All and in a few seconds BBEdit has removed any redundant lines.

Step 2. Remove any duplicate lines

There is a simple built in command to remove any duplicate lines (in this case email addresses) in BBEdit. Under the Text Menu click on the "Process Duplicate Lines Command". I set the parameters as below, clicked on the "Process" button and voila, all my duplicates are now history.

Remove Duplicates

The above tips only scratch the surface of the power of Grep (and BBEdit), but I thought I would share them for 2 reasons; it'll help me remember how I did it and it might help somebody else wrestling with mind-numbing repetitive tasks. For more Grep Help check out BBEdit's Grep Reference under the help menu or try the BBEdit-Talk Board