initial commit
This commit is contained in:
parent
4f88b94244
commit
1087089e98
@ -1,3 +1,6 @@
|
|||||||
# csv-to-vcard
|
# csv-to-vcard
|
||||||
|
|
||||||
convert csv to vcards
|
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.
|
58
csv_to_vcard.sh
Executable file
58
csv_to_vcard.sh
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script:
|
||||||
|
# Version: 1.0
|
||||||
|
# Autor: Marco Morath
|
||||||
|
# Lizenz: Gnu GPLv3 <https://www.gnu.org/licenses/gpl-3.0.html>
|
||||||
|
|
||||||
|
# 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 <input.csv>"
|
||||||
|
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 <<EOL
|
||||||
|
BEGIN:VCARD
|
||||||
|
VERSION:3.0
|
||||||
|
FN;CHARSET=UTF-8:$Vorname $Nachname
|
||||||
|
N;CHARSET=UTF-8:$Nachname;$Vorname;;;
|
||||||
|
KIND;CHARSET=UTF-8:$Typ
|
||||||
|
TEL;type=HOME;VOICE:$Telefon_privat
|
||||||
|
TEL;type=WORK;VOICE:$Telefon_arbeit
|
||||||
|
TEL;type=HOME;CELL:$Telefon_mobil
|
||||||
|
TEL;type=OTHER;VOICE:$Telefon_sonstige
|
||||||
|
TEL;type=HOME;FAX:$Fax
|
||||||
|
TITLE;CHARSET=UTF-8:$Position
|
||||||
|
EMAIL;type=HOME:$EMail_privat
|
||||||
|
EMAIL;type=WORK:$EMail_arbeit
|
||||||
|
EMAIL;type=OTHER:$EMail_sonstige
|
||||||
|
CATEGORIES;CHARSET=UTF-8:$Schlagworte
|
||||||
|
NOTE;CHARSET=UTF-8:$Hinweis
|
||||||
|
ORG;CHARSET=UTF-8:$Firma
|
||||||
|
ADR;type=WORK;CHARSET=UTF-8:;;$Strasse;$Ort;$Bundesland;$PLZ;$Land
|
||||||
|
END:VCARD
|
||||||
|
EOL
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "VCF-Datei erfolgreich erstellt: $OUTPUT_FILE"
|
Loading…
x
Reference in New Issue
Block a user