# Converts tab delimited file converted from gmail export to html # Reads file twice, once to find header # # How to use this: # 1. If you don't know how to run Perl scripts, this is not for you. # 2. Export your contacts to a CSV file in gmail format. # 3. Run this script with the name of the CSV file as its command line argument. # The output is written to standard out. # # Copyright (c) 2006, David Elworthy. # You may freely use and distribute this program, unless you are Richard Stallman, # in which case you are forbidden to use it. use strict; print "\n\nAddress book\n\n\n"; my $file = shift @ARGV; if ($file eq "") { die "Need file name"; } open (F, $file) || die "Cannot open $file"; my @headings = (); while () { if (/^Name\t/) { chomp; @headings = split(/\t/); last; } } close F; my $fields = scalar(@headings); for (my $i = 0; $i < $fields; $i++) { my $f = $headings[$i]; $f =~ s/\r//; $f =~ s/^Section \d+ - //; $headings[$i] = $f; } open (F, $file) || die "Cannot open $file"; while () { my @line = split(/\t/); if ($line[0] ne "Name") { print "

".$line[0]."

\n"; my $held = ""; for (my $i = 1; $i < scalar(@line); $i++) { my $l = $line[$i]; $l =~ s/\r//; chomp $l; $l =~ s/^\"//; $l =~ s/\"$//; if ($l ne "") { # Problem here if we have more fields than headings, but ignore it. my $h = $headings[$i]; if ($h =~ /Description$/) { $held = "".$l."
\n"; } else { print $held."".$h.": ".$l."
\n"; $held = ""; } } } } } close F; print "\n\n";