'
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;;
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
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#*:}"
}