Commit 27860317 authored by Glen Mével's avatar Glen Mével

`read-vcard`: shows phone contacts in human-readable form

parent b89c0dc3
#!/bin/bash
# Usage:
# read-vcard file1.vcf file2.vcf …
# read-vcard < file.vcf
# Show the contents of a vCard file (phone contacts), in a human-readable form.
function comment() { cat; }
cat "$@" \
| comment 'decode Quoted-Printable' \
| perl -MMIME::QuotedPrint -pe '$_=MIME::QuotedPrint::decode($_);' \
| sed 's/;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE//g' \
| comment 'remove some fields' \
| sed '/^VERSION[;:]/d' \
| sed '/^N[;:]/d' \
| comment 'remove BEGIN/END and sort by displayed name (field FN)' \
| sed '/^$/d' \
| sed '/^BEGIN:VCARD$/d' \
| sed 's/^END:VCARD$/\x00/' \
| sed -z 's/^\n//' \
| sort -z \
| sed 's/\x00/\n/' \
| comment 'normalize the formatting of phone numbers (remove spaces, add +33)' \
| sed '/^TEL[;:]/s/ //g' \
| sed '/^TEL[;:]/s/:0\([0-9]\{9\}\)/:+33\1/g' \
| comment 'make French phone numbers more legible (insert spaces)' \
| sed '/^TEL[;:]/s/+33\(.\)\(..\)\(..\)\(..\)\(..\)$/+33 \1 \2 \3 \4 \5/' \
| comment 'simplify the output' \
| sed 's/^TEL;\(.*\):/\1:/' \
| sed 's/^FN://' \
| sed 's/:/: /' \
| less
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment