View Single Post
Posts: 191 | Thanked: 415 times | Joined on Jan 2012
#23
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
 

The Following User Says Thank You to caveman For This Useful Post: