diff --git a/README.md b/README.md index 2d1de19..f49ee7c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ # csv-to-vcard -convert csv to vcards \ No newline at end of file +Shellscript to convert a csv-file to vcards + +Note: +Some Programms read vcard in different ways. It is possible, that the created VCF is not importable in your piece of software. So if you get errors, first check the datastructure, your software is waiting for. The easiest way to get that information should be, to generate a contact on in the software and then to export this vcard to a vcf-file. Compare the software-generated vcf with the entries in the script and edit the script to match the softwares requirements. \ No newline at end of file diff --git a/csv_to_vcard.sh b/csv_to_vcard.sh new file mode 100755 index 0000000..9ad0fcc --- /dev/null +++ b/csv_to_vcard.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Script: +# Version: 1.0 +# Autor: Marco Morath +# Lizenz: Gnu GPLv3 + +# Anwenderhinweis: +# Das Skript erzeugt aus jeder Zeile einer CSV-Datei einen vcard-Eintrag in einer vcard-Datei. +# Somit kann aus einer CSV-Datei mit Kontakten eine importierbare vcard-Datei erzeugt werden. +# Nach dem Dateinamen ist (ggf. mit relativem Pfad) die CSV-Datei anzugeben. +# Als Ausgabe wird die Datei contacts.vcf erzeugt. + +# Überprüfen, ob die Eingabedatei angegeben wurde +if [ "$#" -ne 1 ]; then + echo "Verwendung: $0 " + exit 1 +fi + +# Eingabedatei +INPUT_FILE=$1 + +# Ausgabedatei +OUTPUT_FILE="contacts.vcf" + +# Leere die Ausgabedatei, falls sie existiert +> $OUTPUT_FILE + +# Überspringe die Kopfzeile und lese die CSV-Zeilen +# +2 = Kopfzeile überspringen +# Es müssen alle CSV-Felder in der Reihenfolge der CSV-Datei eingegeben werden (ob diese genutzt werden oder nicht) +# Weitere Informationen zu den Feldbezeichnungen: https://de.wikipedia.org/wiki/VCard#Spezifikation +tail -n +2 $INPUT_FILE | while IFS=';' read -r Typ Vorname Nachname Firma Position Hinweis Schlagworte Telefon_privat Telefon_arbeit Telefon_mobil Fax Telefon_sonstige EMail_privat EMail_arbeit EMail_sonstige Strasse Ort Bundesland PLZ Land +do + cat >> $OUTPUT_FILE <