This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
format-TEL.sh
executable file
·131 lines (120 loc) · 3.63 KB
/
format-TEL.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/sh
#
# NAME
# format-TEL.sh - Format TEL property values
#
# SYNOPSIS
# format-TEL.sh [OPTION...] FILE...
#
# DESCRIPTION
# Uses the national telephone number formatting rules as defined in
# <http://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers>.
#
# BUGS
# https://github.com/l0b0/vcard/issues
#
# COPYRIGHT
# Copyright (C) 2013 Victor Engmark
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
# Sorted by country code
replacements='/^TEL[;:]/{
# NANP countries
s/\(+1\)\([0-9]\{3\}\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
# Netherlands
s/\(+31\)\(6\)\([0-9]\{8\}$\)/\1 \2 \3/ # Mobile
# Belgium
s/\(+32\)\(4[0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}$\)/\1 \2 \3 \4 \5/ # Mobile
# France
s/\(+33\)\([0-9]\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}$\)/\1 \2 \3 \4 \5 \6/
# Switzerland
s/\(+41\)\([0-9]\{2\}\)\([0-9]\{3\}\)\([0-9]\{2\}\)\([0-9]\{2\}$\)/\1 \2 \3 \4 \5/
# United Kingdom
s/\(+44\)\(800\)\(1111$\)/\1 \2 \3/
s/\(+44\)\(845\)\(4647$\)/\1 \2 \3/
s/\(+44\)\(9[0-9]\{2\}\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+44\)\(8[0-9]\{2\}\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+44\)\(8[0-9]\{2\}\)\([0-9]\{6\}$\)/\1 \2 \3/
s/\(+44\)\(7[0-9]\{3\}\)\([0-9]\{6\}$\)/\1 \2 \3/
s/\(+44\)\(500\)\([0-9]\{6\}$\)/\1 \2 \3/
s/\(+44\)\(5[0-9]\{3\}\)\([0-9]\{6\}$\)/\1 \2 \3/
s/\(+44\)\(3[0-9]\{2\}\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+44\)\(2[0-9]\)\([0-9]\{4\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+44\)\(19467\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(17687\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(17684\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(17683\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(16977\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(16977\)\([0-9]\{4\}$\)/\1 \2 \3/
s/\(+44\)\(16974\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(16973\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(15396\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(15395\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(15394\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(15242\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(13873\)\([0-9]\{5\}$\)/\1 \2 \3/
s/\(+44\)\(1[0-9]1\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+44\)\(11[0-9]\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+44\)\(1[0-9]\{3\}\)\([0-9]\{6\}$\)/\1 \2 \3/
s/\(+44\)\(1[0-9]\{3\}\)\([0-9]\{5\}$\)/\1 \2 \3/
# Denmark
s/\(+45\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}$\)/\1 \2 \3 \4 \5/
# Norway
s/\(+47\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{2\}$\)/\1 \2 \3 \4 \5/
# Germany (DIN 5008)
s/\(+49\)\([0-9]\{4\}\)\([0-9]\{6\}$\)/\1 \2 \3/
# New Zealand
s/\(+64\)\([0-9]\{1\}\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
s/\(+64\)\([0-9]\{2\}\)\([0-9]\{3\}\)\([0-9]\{4\}$\)/\1 \2 \3 \4/
}'
sed "$replacements" "$@"