A way to review duplicates in Contacts

Mar 18, '13 07:30:00AM

Contributed by: robleach

Today, I went to send a weekly email to a list I maintain in Contacts, and I noticed that my group had inexplicably lost 7 cards! So I restored the contact cards from Time machine, which allowed me to only "Keep New" ones. However, I ended up with more cards than I knew I was supposed to have.

So I tried using Contacts' "Look for Duplicates" feature, but it would not let me review the duplicates. It simply told me that I had 28 duplicate cards and 8 duplicate entries based on people having the same name, and offered to let me either select Merge or Cancel. I'd sorted out messy merges before, so I wasn't about to get into that morass. So I devised my own way of finding and reviewing duplicates.

First, I selected my group, clicked the name at the top, then Shift-clicked the last name to highlight all the cards. I then dragged them into the to field of an empty email. I then typed Command-A to select them again and pasted them into a temporary TextEdit plain text document which I named "dupe_search.txt". (If anyone knows a way to skip the email/drag step, let me know.) I then ran the text document through this set of piped commands in Terminal:

cut -f 2 -d '<' dupe_search.txt | cut -f 1 -d '>' | sort | uniq -c | grep -v "   1 "
This returns a list of email addresses with the number of times they occur in Contacts to the left. I then manually searched for each one in Contacts to inspect the dupes.

To merge the cards, select them and just type Command-Shift-| or select "Merge Selected Cards" from the Card menu.

I remembered after doing this that most of my missing cards had been a series of duplicates I'd previously merged a week ago! But I did recover 4 that had apparently slipped through Apple's cracks.

Be wary about maintaining lists in Contacts, especially if you use iCloud. I have found some disturbing bugs, such as when you right-click on a group and select "Send email to '...'", I wasn't getting the same number of email addresses as when I manually selected all the cards in that group and dragged them to the email! I've been adding emails via my iPhone - and I'm not sure I trust that iCloud is syncing them correctly given these four recovered cards!

[kirkmc adds: I haven't tested this. I have often had problems with Contacts, however, especially with certain cards having multiple email addresses that come from other cards. I wish there were a better way to clean out the Contacts database.]

Comments (8)

Mac OS X Hints