#!/bin/bash
# This script contains some bashisms and therefore may need bash,
# especially the counter arithmetic is bashy
#
# Besides that, this script parses a single vcf file generated by many
# Sony Ericsson phones and produces single vcf files (one per contact)
# suitable for importing them into Outlook, etc.
#
# by Alexander Griesser <work@tuxx-home.at> 2007
die() { echo "$*"; exit 1; }
[ "$#" = "1" ] || die "usage: $(basename $0) phonebookfile.vcf"
[ -r "$1" ] || die "cannot read $1"
COUNTER=0
while read line; do
echo "$line" >>$COUNTER.vcf
if echo "$line" | grep -q "^END:VCARD"; then
COUNTER=$((COUNTER + 1))
fi
done < $1