-
Notifications
You must be signed in to change notification settings - Fork 8
/
vcf2list
executable file
·47 lines (39 loc) · 1.45 KB
/
vcf2list
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
#!/usr/bin/awk -f
# vcf2list (AWK script) -- Converts a vCard file into one line of CSV, plus e-mail
BEGIN { FS=":" }
/^BEGIN:VCARD/ { name = ""; fullname = ""; addr_qty = ""; delete phones; email = ""; }
# Clean up DOS line endings
/\r$/ { $0 = substr($0, 1, length($0) - 1); }
## $1 ~ /^N\>/
$1 == "N" {
# parts =
name_qty = split($2, name_parts, /;/);
name = name_parts[1] ", " name_parts[2];
fullname = name_parts[2] " " name_parts[1]
## print fullname
}
$1 ~ /^ADR/ {
# parts =
addr_qty = split($2, parts, /;/);
if (addr_qty == 4)
addr = parts[2] " " parts[3] " " parts[4];
else
addr = parts[2] " " parts[3]
}
$1 ~ /^TEL/ {
pos = index($1, "=")
if (pos > 0)
type = substr($1, pos + 1)
else
type = "default"
phones[type] = $2
}
$1 ~ /^EMAIL/ { email = $2 }
END {
phone_str = ""
for (type in phones) phone_str = phone_str " " phones[type]
phone_str = substr(phone_str, 3)
printf("\"%s\",\"%s\",\"%s\",\"\"\n", name, phone_str, addr)
if (email)
print "alias " tolower(name_parts[2]) " " fullname " <" email ">"
}