<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Joe Maller &#187; vcard</title>
	<atom:link href="http://joemaller.com/tag/vcard/feed/" rel="self" type="application/rss+xml" />
	<link>http://joemaller.com</link>
	<description>.com</description>
	<lastBuildDate>Fri, 27 Jan 2012 06:04:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Fixing a Palm duplicate disaster</title>
		<link>http://joemaller.com/888/fixing-a-palm-duplicate-disaster/</link>
		<comments>http://joemaller.com/888/fixing-a-palm-duplicate-disaster/#comments</comments>
		<pubDate>Sun, 17 Feb 2008 07:17:05 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[misc.]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[Palm]]></category>
		<category><![CDATA[Palm Desktop]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[vcard]]></category>

		<guid isPermaLink="false">http://joemaller.com/2008/02/17/fixing-a-palm-duplicate-disaster/</guid>
		<description><![CDATA[I recently came across an absolute disaster of a Palm Desktop data file while helping someone setup a new iPhone. It had 13,572 contacts, mostly duplicates. Judging from the number of obvious duplicate entries, my guess is the actual number will be somewhere around 2500 (it was). Here is the process I used to automatically [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across an absolute disaster of a Palm Desktop data file while helping someone setup a new iPhone. It had 13,572 contacts, mostly duplicates. Judging from the number of obvious duplicate entries, my guess is the actual number will be somewhere around 2500 (it was).</p>
<p>Here is the process I used to automatically remove a lot of those duplicates and import the remainder into the Mac&#8217;s Address Book. </p>
<p>The first step is to get out of Palm Desktop as soon as possible. Select all contacts and export to a group VCard. This one was 3.4 MB.</p>
<p>Most of this will happen in Terminal, but a quick stop in BBEdit or <a href="http://www.barebones.com/products/textwrangler/">TextWrangler</a> will save a few steps later on. (TextMate tends to choke on big, non-UTF files.) The Palm export file is encoded in MacRoman. It&#8217;s 2008, pretty much any text that isn&#8217;t Unicode should be. I used TextWrangler to convert the encoding to UTF-8 no BOM (byte order marker).</p>
<p>VCards require Windows style CRLF line endings. While we could deal with those in Sed, we might as well just switch the file to Unix style LF endings in TextWrangler too. The TextWrangler bottom bar should switch from this:  </p>
<p><img src='http://joemaller.com/wordpress/wp-content/uploads/2008/02/macroman_crlf.png' alt='MacRoman CRLF' /></p>
<p>To this:</p>
<p><img src='http://joemaller.com/wordpress/wp-content/uploads/2008/02/utf8_lf.png' alt='utf8 LF' /></p>
<p>Now comes the <a href="http://sed.sourceforge.net/sed1line.txt">magic</a>.</p>
<p>While this could be done as an impossible-to-read one-line sed command, it&#8217;s easier to digest and debug as separate command files.</p>
<p>Here are the steps:</p>
<ol>
<li>Use Sed to join each individual VCard into a single line using a token to replace line feeds, output to intermediate file</li>
<li>Sort and Uniq the result to remove obvious duplicates.
<li>Replace the tokens with line feeds</li>
</ol>
<p>Below are the two sed command files I used. I ran these individually but they could easily be piped together into a one-line command.</p>
<p><em>vcard_oneline.sed:</em></p>
<pre><code># define the range we'll be working with
/BEGIN:VCARD/,/END:VCARD/ {

# define the loopback
:loop

# add the next line to the pattern buffer
N

# if pattern is not found, loopback and add more lines
/\nEND:VCARD$/! b loop

# replace newlines in multi-line pattern
s/\n/   %%%     /g
}</code></pre>
<p>Run that like this:  </p>
<pre><code>sed -f vcard_oneline.sed palm_dump.vcf &gt; vcards_oneline.txt</code></pre>
<p>Then run that file through sort and uniq: </p>
<pre><code>sort vcards_oneline.txt | uniq &gt; vcards_clean.txt </code></pre>
<p><em>vcard_restore.sed:</em></p>
<pre><code># replace tokens with DOS style CRLF line endings
s/      %%%     /^M\
/g

# add the &lt;CR&gt; before the LF at the end of the line
s/$/^M/</code></pre>
<p>Run that with something like this:  </p>
<pre><code>sed -f vcard_restore.sed vcards_clean.txt &gt; vcards_clean.vcf</code></pre>
<p>After that last step, you should be able to drag the vcards_clean.vcf file into Address Book to import your vcards.</p>
<p>Suggestions for improvement are always welcomed.</p>
<h3>Notes:</h3>
<p>In VIM, type the tab character as control-v-i (hold control while pressing v then i), type the <CR> line break by typing control-v-enter.</p>
<p><code>iconv</code> could be used to convert from MacRoman to UTF-8. TextWrangler just seemed easier at the time.</p>
<p>Palm Desktop appears to dump group VCards in input order, so duplicate entries were not grouped together. Running the output through <code>sort</code> visually reveals a ton of duplicates and makes it possible to use <code>uniq</code> to remove consecutive duplicates.</p>
<p>I had to quit and re-open Address Book once or twice before it would import the files.</p>
]]></content:encoded>
			<wfw:commentRss>http://joemaller.com/888/fixing-a-palm-duplicate-disaster/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Database Caching 1/10 queries in 0.009 seconds using disk: basic
Object Caching 225/237 objects using disk: basic

Served from: joemaller.com @ 2012-02-08 12:10:15 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          tag/vcard/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.459s
Header info:
Set-Cookie:         bb2_screener_=1328721015+38.107.179.219+38.107.179.219; path=/
X-Pingback:         http://joemaller.com/wordpress/xmlrpc.php
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Wed, 08 Feb 2012 17:10:15 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Wed, 08 Feb 2012 18:10:15 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               59291eb04a3fff016a946c209055badd
X-Powered-By:       W3 Total Cache/0.9.2.4
Content-Encoding:   gzip
-->
