blob: 61772ed20e45299be613146a18ed651a42ac55b0 (
plain)
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
|
#!/bin/sh
green="\033[0;32m"
lgreen="\033[0;36m"
nocol="\033[0m"
[ -z "$1" ] || [ -z "$2" ] && {
printf "Usage:$green xlsx-to-vcards.sh file.xlsx output-dir\n"
printf "$lgreen output-dir$nocol will be filled with .vcf files\n"
exit 1
}
printf "Converting to csv..\n"
#libreoffice --headless --convert-to csv "$1" --outdir /tmp/
[ -d "$2" ] || {
printf "Dir %s doesn't exit, creating..\n"
mkdir -pv "$2" || exit 1
}
OUTD="$2"
bname="${1##*/}"
csvfname="/tmp/${bname%.*}.csv"
echo "$(file "$csvfname")"
create_vcf() {
[ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] && {
printf "Invocation (no spaces in names/p.numbers):\n"
printf "create_vcard last_name first_name phone\n"
exit 1
}
uid=$(uuidgen -s -n @oid -N $1_$2)
ofname="${OUTD}/${uid}.vcf"
printf "BEGIN:VCARD\nVERSION:3.0\n" > $ofname
printf "UID:%s\n" $uid >> $ofname
printf "FN:%s %s\n" $2 $1 >> $ofname
printf "TEL;TYPE=cell:+%s\n" $3 >> $ofname
printf "END:VCARD" >> $ofname
unix2dos $ofname
}
for trip in $(strings "$csvfname"|sed -E 's/[",]/ /g;s/7-9/79/g'|
awk 'NR>1 {printf "%s_%s_%s\n", $2, $3, $NF}')
do
fname=${trip%_*}
fname=${fname#*_}
create_vcf ${trip%%_*} $fname ${trip##*_}
done
|