As you may or may not know already, all mobile phone numbers in Mauritius are shifting to 8 digit numbers as from 1st September 2013. So if your number is 777-8888, it will become 5777-8888. So to call or SMS you, I’d need to put a 5 in front of your number. Same for SMS. More info from Emtel here.
The problem is how to change all your mobile contact numbers to add that 5 before. I hear the various mobile operators are developing mobile apps to handle it for you, but I wanted a DIY way for my S3. If you have a similar DIY way for your own mobile, feel free to share in the comments. This article is NOT a guide, but merely the steps I will take to add 5 to my own numbers. It may, or may not work for you so use at your own risk. I hope I don’t end up with a horribly broken contact list! :/ Feel free to suggest if you have a better idea, apart from using an app coded by a third-party. I’m interested in DIY methods, or how you are planning to do your own migration if your phone doesn’t have an app.
Here’s my plan:
Let me just say this here: If you follow these steps and break something or mess up your contacts, I’m not responsible and am not fixing it for you. Use at your own risk!
1. Sync phone numbers with Google’s servers.
On my phone:
Menu → Settings → Accounts → Google → (select your account) → ensure “Sync Contacts” is checked → touch “Sync Now” button.
Just to make sure I have a secondary backup if I need:
Phone → Contacts → Menu button → Import / Export → Export to SD Card
At this point, I’d turn off internet connectivity from my phone, so I turn off Mobile Data and Wifi from the Notification Panel.
2. Get a CSV file from Google
Download a CSV file containing my numbers. Make a backup of the file and modify the copy.
Login to your Gmail account using your Google account that you use with your phone.
On the left, where it says “Gmail”, click on it to get a drop-down menu and select contacts.
Click on the “Square” icon button and choose “Select All”.
Click the “More” button → Export
Select “All Contacts” just to be sure you’ve selected everything. Export Format = Google CSV. You’re going to import back to Google anyway.
You’ll end up with a file with your contact names, details and phone numbers separated by commas.
Make a copy of that file somewhere. We’ll modify the original. Keep the copy safe.
3. Delete your phone numbers!
That’s the actual dangerous step: Delete the phone numbers from Google’s servers and your own device.
To delete contacts on your phone:
Phone → Contacts → Menu button → Delete → check Select All → touch Delete button.
To delete from Google’s side:
Select all your contacts as in previous step → click “More” button → Delete Contacts
4. Regex magic
Use Regex to match mobile numbers and add 5 in front.
I’m using Notepad++ for the regex replacement job.
Open the file you got from Google. It was called google.csv for me.
You’ll get a series of lines that look like this. Since I’m lazy and don’t populate my contacts’ details, my file’s fields are mostly blank:
Contact Name,,,Contact Name,,,,,,,,,,,,,,,,,,,,,,,* My Contacts,,,,,Mobile,<number here>,,,,
I want to replace all mobile phone numbers. I got the mobile prefixes used in Mauritius and using some regex, do the 5-adding task with search and replace. I just hope that ICTA keeps the prefixes are up to date.
From Notepad++, Search menu → Replace
search mode = Regular expression
Find what = \b(230)?((?:25\d|29\d|42[1-3]|42[8-9]|44\d|49\d|7[0-9]\d|82\d|86\d|871|87[5-8]|9[0-8]\d)(?:-| )?(?:\d{4}))\b
Replace with = \15\2
Click “Replace All” button. Check if your phone numbers have been correctly replaced. You may of course have to tweak that regex line for your own needs. It works for me.
Save the file.
If you want to know, that regex above looks for this:
1. Has to start with a word boundary. We’re looking for exact matches. Same for line 7, which ends the matching. We only want Mauritian numbers, so starting with +230. We don’t care about +. +230 might not be there.
3. Match the mobile prefixes e.g. 421, 422 etc. for numbers such as 422-1234. 25\d means 25 followed by any single digit e.g. 252.
4. Some of my numbers have separators: space or dash. Some don’t. Cater for that.
5. Match the number suffix e.g. 422-1234, the 1234 part.
Replace with: \15\2 means put the first group (\1 = 230), followed by ‘5’, then the 2nd group (\2 = remaining part of number).
Edit: Thanks to @Carrotmadman6 for pointing out a mistake in the regex causing it to match non-Mauritian numbers. Fixed it. Should be working fine now. Please let me know if you find other errors.
Edit2: Fixed a mistake regarding handling of +230.
5. Import changes to Google
Import the modified list back to Google contacts.
In your Google account → Contacts, click “More” button → Import → point to that .CSV file you just modified and click “Import”.
6. Sync device with Google to download the updated phone numbers.
On your phone, switch on Wifi / Mobile data. Then,
Menu → Settings → Accounts → Google → (select your account) → ensure “Sync Contacts” is checked → touch “Sync Now” button.
7. Hope everything went well and I don’t end up with a completely broken contact list!
Well, I hope I don’t make a gigantic mess out of my contacts list while doing those steps! But hey, using an app is too easy! I’d rather do it the DIY way!
So, got any other methods for other devices? Ideas? Better method for Android? Drop a comment! Thanks!