maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   Convert all Contact Numbers (https://talk.maemo.org/showthread.php?t=83052)

sensortk 2012-03-15 16:39

Convert all Contact Numbers
 
Hi
According to the ministry of communication in my country, All communications companies are changing all mobile numbers by adding a single digit to all numbers and I need a script to edit my contacts cuz I cannot edit them manually , it's impossible

the script should do the following
all numbers begininig with 011 or 014 or 0152 ... another 1 should be added after the first 1 so they become 0111, 0114 , 01152
and all 010, 016, 0151 should be 0100, 0106, 01051
and all 012, 018, 0150 should be 0122, 0128, 01250

can anyone even tell me how to write scripts .. I already have a good background in C/C++ programming
because the deadline is this month !!!! or i wont be able to use the old numbers
Thanks alooot

zlatko 2012-03-15 17:02

Re: Convert all Contact Numbers
 
I think easiest solution is:
1. Export all contacts.
2. Concatenate all produced .vcf files to one long .vcf file containing all your contacts.
3. Using vi editor(or one of your choice) replace all numbers you want.
4. Re-import the edited multicontact .vcf file in your phonebook.

No need of programming skills and will take 5 minutes.

louiegoat 2012-03-15 17:06

Re: Convert all Contact Numbers
 
So does that mean all the mobile phones in your country will not work at the end of the month ? What country are you in ? What part of the phone number are you referring to ? All new phones allows you edit numbers , unless I'm missing something!

drzmbs 2012-03-15 23:20

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by sensortk (Post 1179881)
Hi
According to the ministry of communication in my country, All communications companies are changing all mobile numbers by adding a single digit to all numbers and I need a script to edit my contacts cuz I cannot edit them manually , it's impossible

the script should do the following
all numbers begininig with 011 or 014 or 0152 ... another 1 should be added after the first 1 so they become 0111, 0114 , 01152
and all 010, 016, 0151 should be 0100, 0106, 01051
and all 012, 018, 0150 should be 0122, 0128, 01250

can anyone even tell me how to write scripts .. I already have a good background in C/C++ programming
because the deadline is this month !!!! or i wont be able to use the old numbers
Thanks alooot

اخي في برنامج بمتجر نوكيا اسمه MeegoEgypt cotact Modifier

Dear There is an APP. for this Prob it's "MeegoEgypt cotact Modifier" you can find it in STORE of N9

sensortk 2012-03-16 11:54

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by zlatko (Post 1179892)
I think easiest solution is:
1. Export all contacts.
2. Concatenate all produced .vcf files to one long .vcf file containing all your contacts.
3. Using vi editor(or one of your choice) replace all numbers you want.
4. Re-import the edited multicontact .vcf file in your phonebook.

No need of programming skills and will take 5 minutes.

Thanks for your care :)

nice simple way :) but whats VI editor ? how can I make it edit all numbers in the vcf file ??

sensortk 2012-03-16 12:00

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by louiegoat (Post 1179894)
So does that mean all the mobile phones in your country will not work at the end of the month ? What country are you in ? What part of the phone number are you referring to ? All new phones allows you edit numbers , unless I'm missing something!

you got it all wrong :D
the first part of all numbers are edited because numbers are increasing and the 7 digit number isnt enough for the increasing mobile phones becides... to unify the first 3 digits for each of the three communication companies (all the first company customers will begin with 010 and the second will be 011 and third will be 012 ..)

anyway there have been many android, BB, iOS and Nokia symbian apps for this issue but noone made an app for N900 :S and I cant edit 500 contacts manually man !!

i.e: all phones in my country will work except mine :D

sensortk 2012-03-16 12:02

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by drzmbs (Post 1180055)
اخي في برنامج بمتجر نوكيا اسمه MeegoEgypt cotact Modifier

Dear There is an APP. for this Prob it's "MeegoEgypt cotact Modifier" you can find it in STORE of N9

ok thats a meego app .. will it work on maemo ??

louiegoat 2012-03-16 18:57

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by sensortk (Post 1180203)
you got it all wrong :D
the first part of all numbers are edited because numbers are increasing and the 7 digit number isnt enough for the increasing mobile phones becides... to unify the first 3 digits for each of the three communication companies (all the first company customers will begin with 010 and the second will be 011 and third will be 012 ..)

anyway there have been many android, BB, iOS and Nokia symbian apps for this issue but noone made an app for N900 :S and I cant edit 500 contacts manually man !!

i.e: all phones in my country will work except mine :D

Oh okay. So then it would be like an area code plus another three digits and then your seven digit phone number is that correct ? Eventually they would have to do something since almost every person now has a cell phone. Hope you find a solution soon, good luck !

zlatko 2012-03-21 13:33

Re: Convert all Contact Numbers
 
@sensortk
vi editor is text editor with text ui. Very powerful and widely used on *nix OS.
It is very simle to do such substitutions once you have learned it. Here is an example. Let suppose the number you want to change is: +555 012 123 456 In .vcf line with that mobile number looks like this:
Code:

TEL;TYPE=CELL:+55512123456
In it if you want to convert all numbers starting with (0)12 to (0)122 you use this command:
Code:

:%s/+55512/+555122/g
This will substitute all occurrences of "+55512" to "+55122", will take you like 1 minute.
You have to do this for all codes you want to change.

saponga 2014-04-30 12:14

Re: Convert all Contact Numbers
 
Does anyone managed to deal with that task ? I'm in the same situation... :( I need to add a "9" before every phone number that BOTH starts with 9 or 8 AND have 8 digits and wouldn't like to edit every each .vcf on a text editor. Does anyone wrote a script that i can adapt to my case ? i'd be eternally gratefull if someone share such piece of code.

Obsidian 2014-04-30 13:54

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by saponga (Post 1423479)
Does anyone wrote a script that i can adapt to my case ?

Try this in the folder where your vcf files are:
Code:

grep -l ':+[89][0-9]\{7\}$' *.vcf | xargs sed -i '/:+[89][0-9]\{7\}$/s/\+/\+9/g'
I'm not sure if I installed sed from the repositories or if it's part of maemo anyway. So If sed is not found, you'll have to install it.

Aonsaithya 2014-04-30 13:57

Re: Convert all Contact Numbers
 
I'd just sync the contacts to Outlook or similar, export them to an excel file, modify the information with functions or such and finally reverse the process to get the updates to the phone.

In fact, I think I have done that some time in the past.

saponga 2014-04-30 14:23

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by Obsidian (Post 1423491)
Try this in the folder where your vcf files are:
Code:

grep -l ':+[89][0-9]\{7\}$' *.vcf | xargs sed -i '/:+[89][0-9]\{7\}$/s/\+/\+9/g'
.

Thanks bro... I did try it on my kali box but:
Code:

~/Exported contacts$ grep -l ':+[89][0-9]\{7\}$' *.vcf | xargs sed -i '/:+[89][0-9]\{7\}$/s/\+/\+9/g'
sed: no input files

I should try to debug your line but i really didn't understand anything :)
And, yes, the .vcf files are in that folder. Am i missing something ?

edit: busybox gives me another output:
Code:

~/MyDocs/Exported contacts $ grep -l ':+[89][0-9]\{7\}$' *.vcf | xargs sed -i '
/:+[89][0-9]\{7\}$/s/\+/\+9/g'
sed: -i requires an argument

Thanks again buddy !!!

saponga 2014-04-30 14:31

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by Aonsaithya (Post 1423492)
I'd just sync the contacts to Outlook or similar, export them to an excel file, modify the information with functions or such and finally reverse the process to get the updates to the phone.

That is a good idea... Although i'll wait and see if someone has already managed to solve that situation using (b)ash. :)
Thanks for the tip !!!

Obsidian 2014-04-30 22:31

Re: Convert all Contact Numbers
 
The command should be in one line with no breaks.

It's a combination of two commands: the grep lists all the files that match the pattern (regular expression) and hands them over to the sed, that does the find & replace part.

If the grep doesn't find any files, it won't work. The pattern I used is:
1. a colon (:)
2. a plus-sign (+)
3. either 8 or 9
4. seven digits (from 0 to 9)
5. end of line ($)

Maybe you find a pattern that works or you give me an anonymised vcf-file for testing purposes.

caveman 2014-04-30 23:51

I have a quick script for the br scenario. I look 4 it and post later.

saponga 2014-05-01 00:48

Re: Convert all Contact Numbers
 
1 Attachment(s)
Quote:

Originally Posted by Obsidian (Post 1423564)
The command should be in one line with no breaks.

Well... i just did a copy/paste... :confused:
Quote:


It's a combination of two commands: the grep lists all the files that match the pattern (regular expression) and hands them over to the sed, that does the find & replace part.

If the grep doesn't find any files, it won't work. The pattern I used is:
1. a colon (:)
2. a plus-sign (+)
3. either 8 or 9
4. seven digits (from 0 to 9)
5. end of line ($)
Thanks for your patience. I'll try to understand that line for sure.

Quote:

Maybe you find a pattern that works or you give me an anonymised vcf-file for testing purposes.
Thanks again. I'm attatching a .vcf file.

saponga 2014-05-01 00:49

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by caveman (Post 1423578)
I have a quick script for the br scenario. I look 4 it and post later.

I'll really apreciate that. Thanks.

Obsidian 2014-05-01 08:05

Re: Convert all Contact Numbers
 
I see, there's no leading plus sign. Just remove it from the pattern in the grep command and in the sed command and it should work:
Code:

grep -l ':[89][0-9]\{7\}$' *.vcf | xargs sed -i '/:[89][0-9]\{7\}$/s/\+/\+9/g'

peterleinchen 2014-05-01 19:56

Re: Convert all Contact Numbers
 
@saponga
Is this
Code:

sed  '/:[89][0-9]\{7\}\>/s/:/:9/g' -i *.vcf
what you are looking for?

@obsidian
there should be no need for xargs, or?
$ did not work so I used \>

saponga 2014-05-01 20:51

Re: Convert all Contact Numbers
 
Quote:

Originally Posted by peterleinchen (Post 1423735)
@saponga
Is this
Code:

sed  '/:[89][0-9]\{7\}\>/s/:/:9/g' -i *.vcf
what you are looking for ?

Woow \o/ Thank you very much !!! It worked like a charm.

peterleinchen 2014-05-01 20:56

Re: Convert all Contact Numbers
 
You are welcome.

obsidian was almost right:
But/And I do also understand why the $ (end of line anchor) did not work but \> (end of word) does?

caveman 2014-05-02 19:40

Re: Convert all Contact Numbers
 
Recently I formatted all my numbers. The procedure used a small shell script and a sed script, and was run on the N9.


The steps are as follows:
0. make a backup and verify it works
1. clear the contacts dir
2. export all contacts to vcf files
3. run the script in the contacts dir
4. delete all contacts
5. reimport them as follows: in the contacts dir, do a "cat *.vcf > all.vcf" and import the all.vcf file.

Here follows the scripts I used. First the shell script:
Code:

#!/bin/sh

# TEL;TYPE=CELL,VOICE:0118765-4321
for i in *.vcf; do
        sed -i -r -f 9th-digit-tim.sed $i
done

The sed script improves the number presentation, inserts the 9th digit and operator code.

Please test and adapt to your case before using on the device.
Code:

# remove format chars
/^TEL/        s/[\(\)\ \.-]//g
# cell phones of SP with 8 digits -> 0 41 DDD 9XXXX
/^TEL/        s/:(1[1-9])([6-9][0-9]{3})([0-9]{4})/:0 41 \1 9\2 \3/p
/^TEL/        s/:0(1[1-9])([6-9][0-9]{3})([0-9]{4})/:0 41 \1 9\2 \3/p
# cell phones without ddd
/^TEL/        s/:([6-9][0-9]{3})([0-9]{4})/:9\1 \2/p
# cell phone with ddd
/^TEL/        s/:([2-9][1-9])([6-9][0-9]{3})([0-9]{4})/:0 41 \1 \2 \3/p
/^TEL/        s/:0([2-9][1-9])([6-9][0-9]{3})([0-9]{4})/:0 41 \1 \2 \3/p
# non-cell phones
/^TEL/        s/:([2-5][0-9]{3})([0-9]{4})/:\1 \2/p
/^TEL/        s/:(1[1-9])([2-5][0-9]{3})([0-9]{4})/:0 41 \1 \2 \3/p
/^TEL/        s/:0(1[1-9])([2-5][0-9]{3})([0-9]{4})/:0 41 \1 \2 \3/p



All times are GMT. The time now is 04:38.

vBulletin® Version 3.8.8