From a76ef45bd763687be2e517955bc50089adaa64ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Tue, 14 May 2019 14:21:51 +0200 Subject: [PATCH] update_attribute function --- pdiread.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pdiread.sh b/pdiread.sh index d2eb9fa..d774ada 100755 --- a/pdiread.sh +++ b/pdiread.sh @@ -27,6 +27,11 @@ BR=' ' pdi_load() { + # normalise PDI file for processing with pdi_* functions + # functions in this library can only be applied to normalised data + # Usage example: + # data="$(pdi_load file.vcf)" + sed -En ' # === Read entire file into buffer === :X $bY; N; bX; :Y s;^.*$;\n&\n;; @@ -132,7 +137,7 @@ pdi_update_value(){ local card="${BR}$1" name="$2" cnt="$3" val="$4" while [ "$cnt" -gt 0 ]; do if [ "${card#*${BR}${name};*:}" = "${card}" ]; then - printf '%s\n%s;:' "${card%${BR}END:VCARD*}" "${name}" + printf '%s\n%s;:' "${card%${BR}END;:VCARD*}" "${name}" card="${BR}END;:VCARD" break; else @@ -143,6 +148,21 @@ pdi_update_value(){ fi cnt=$((cnt - 1)) done - printf '%s\n' "$val" - printf '%s\n' "${card#*${BR}}" + printf '%s\n%s\n' "$val" "${card#*${BR}}" +} + +pdi_update_attrib(){ + local card="${BR}$1" name="$2" cnt="$3" val="$4" + while [ "$cnt" -gt 0 ]; do + if [ "${card#*${BR}${name};*:}" = "${card}" ]; then + printf '%s\n%s;' "${card%${BR}END;:VCARD*}" "${name}" + card=":${BR}END;:VCARD" + break; + else + printf '%s\n%s;' "${card%%${BR}${name};*}" "${name}" + card="${card#*${BR}${name};}" + fi + cnt=$((cnt - 1)) + done + printf '%s:%s\n' "$val" "${card#*:}" } -- 2.39.2