Yes, this post is indeed about a Quick and Dirty tool to “Convert a Wammu backup file to a .csv” ready for gMail import. I dicked around with the wammu.backup file to get it to plain text for reference and then figured Id better write some quick perl to get it to a .csv so I could import that into my gMail account. Since my Android phone automagically synchronizes with my gMail contacts (gotta love it)
I started writing the perl after I dicked around a bit with the file. The file is by default DOS formatted, illegible and apparently encoded in utf-16. Since I first wanted it as a reference (to grep, cat or less in a term window) so I did the following. You ll have to do this too (do feel free to submit the Perl code in the comments to skip this part
)
- Open the file using vi.
- Save file (yes, save BEFORE editing, this converts the binary to a regular file)
:w ConvertMe.txt
- If the conversion using vi doesnt work for you, you can also use flip (Thanks to AK for the tip, check his comment for more info!)
flip -ub ConvertMe.txt
- If the conversion using vi doesnt work for you, you can also use flip (Thanks to AK for the tip, check his comment for more info!)
- Set unix encoding
:set ff=unix
- Reset the encoding
:set fileencoding=default
- Save! (use the :w)
Next part is the Perl script. (The code is after the jump..)
The script reads a file called ConvertMe.txt – You can change this in the script, but really, why
- run convert.pl , this will output the .csv on the screen
- run convert.pl > converted.csv to get the google ready csv..
Importing into gMail is really simple. Login and click “Contacts” (Left sidebar), click “Import” (on top of the contacts list to the right) and import it using the menu. I imported slightly over 260 contacts and decided it was a bad idea seconds later since I now have a lot of work to sort those out. Thats a pain in the arse. And Im not sure why, but the find duplicates doesnt find nearly half of them. Apparently it doesnt compare the phone nrs. Probably something to do with false positives.. Cool option though.. I DID import them into a separate category and that does help! Beats doing them by hand..
What if this doesnt work?
There are three options for output..
You ll find the following in the code. Its not that long, do a search
# Print de codes?
my $codes = 1;
to print all the codes in the file you re having parsed. This reads the file and spews out all the different tags in there in an easy list.
# Print de raw data
my $raw = 1;
Print the raw data. Prints all the tags for every contact, so you dan easilly check if all looks right
# Print de geparste code
my $parse = 1;
This is enabled by default. This option parses all your data into the .csv format.
If the last fails, its possible you need to change or add to the tags described in the .csv file. This defenition starts at line 66, the # Parse data line. First check what tags your file provides by setting the $codes option and then fill these in on the right lines in the script. Dont remove the commas or the .csv will fail to parse correctly. Just add the fields in front, analogous to the current settings. Dont worry about the tags that wont be filled, they will be empty. Dont worry, it ll work
The Source.. Moved to http://www.gertschepens.be/wammu2cvs-code
Edit: People have been experiencing problems with the code and after a long and hard look I discovered the error to be the blog having stripped the <MYFILE> from the code, thinking it to be faulty html and thus creating an endless loop.. This explains a lot
Kudos to AK for helping me sort it all out! And sorry for the mess..
Edit2: Code moved to http://www.gertschepens.be/wammu2cvs because of formatting problems in this post.


Hi Nils,
glad you figured it out! One of the previous commenters also used iconv or a similar tool to convert and posted an updated blob of code. I’ll see about making that update more prominently visible in here..
thanks for commenting