Logo

VCF2CSV

Dieses kleine Skript liest ein angegebenes VCF Adressbuch aus und gibt es als CSV über die Standardausgabe zurück.
Das ganze habe ich nur mit dem Adressbuch meines Mobiltelefones getestet. Sonderzeichen können Probleme verursachen!

vcf2csv.sh
#!/bin/bash

# vcf2csv.sh, convert vcf to csv Copyright (C) 2005 Moritz Kobel,
#
# 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 2 of the License.
# 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
# Licence for more details.
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA




if [ -e $1 ]
then
# open file -> 3
FILE=$1
exec 3<> $FILE
else
echo "FILE ERROR: run: $0 vcf-file"
exit -2
fi


# Read file,...
while read -u 3 DATA
do
# get type
TYPE=`echo $DATA | awk -F':' '{print $1;}'`
case "$TYPE" in
BEGIN)
# RESET Variables
NAME=""
VNAME=""
NNAME=""
TEL_HOME=""
TEL_MOBIL=""
TEL_FAX=""
TEL_WORK=""
TEL_OTHER=""
EMAIL=""
;;
"N;ENCODING=QUOTED-PRINTABLE")
# Try to decode name
NAME=`echo $DATA | awk -F':' '{print $2;}'`
NAME=`echo $NAME | sed -e s/=FC/ue/g`
NAME=`echo $NAME | sed -e s/=E4/ae/g`
NAME=`echo $NAME | sed -e s/=F6/oe/g`
NAME=`echo $NAME | sed -e s/=E9/é/g`
;;
N)
# simple name
NAME=`echo $DATA | awk -F':' '{print $2;}'`
;;
TEL)
# phone, other
TEL_OTHER=`echo $DATA | awk -F':' '{print $2;}'`
;;
"TEL;HOME")
# phone, home
TEL_HOME=`echo $DATA | awk -F':' '{print $2;}'`
;;
"TEL;WORK")
# phone, work
TEL_WORK=`echo $DATA | awk -F':' '{print $2;}'`
;;
"TEL;FAX")
# phone, fax
TEL_FAX=`echo $DATA | awk -F':' '{print $2;}'`
;;
"TEL;CELL")
# phone, mobile
TEL_MOBIL=`echo $DATA | awk -F':' '{print $2;}'`
;;
"EMAIL;INTERNET;PREF")
# email address
EMAIL=`echo $DATA | awk -F':' '{print $2;}'`
;;
END)
# end of card -> print output

# split name
VNAME=`echo $NAME | awk -F';' '{print $2;}'`
NNAME=`echo $NAME | awk -F';' '{print $1;}'`

## OUTPUT: ##
echo ${NNAME}","${VNAME}","$TEL_HOME","$TEL_MOBIL","$TEL_FAX","$TEL_WORK","$TEL_OTHER","$EMAIL
;;
VERSION|TITLE|ORG)
# just ignore this ones....
;;
*)
# oops... unknown data
echo "UNKNOWN: $DATA"
;;
esac
done
# Close file
exec 3<&-

exit 1

powered by ITDS WebAdministrator 4.2r6735@stockhorn/jwa