Created
October 3, 2011 16:15
-
-
Save lamberta/1259497 to your computer and use it in GitHub Desktop.
Formats a Google contacts list for use in a Pine address book.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
##Formats a Google contacts list for use in a Pine address book. | |
##Requires the Google Command Line Tool: http://code.google.com/p/googlecl/ | |
##Usage: | |
## contacts-to-addressbook > $HOME/.addressbook | |
GOOGLECL=$(which google) | |
if [ ! -x "$GOOGLECL" ]; then | |
echo "Error: Requires the Google command line tool." | |
exit 1 | |
fi | |
while read line; do | |
#parse fields | |
name=$(echo "$line" | cut -d "," -f1) | |
email=$(echo "$line" | cut -d "," -f2 | cut -d ";" -f1) #primary email | |
#don't add contact without an email address | |
if [ -n "$email" ]; then | |
#format entry for pine address book: nick[TAB]full[TAB]email | |
echo -e "\t$name\t$email" | |
fi | |
#ignore google voice numbers | |
#replace empty fields, alphabetical sort | |
#empty names last | |
done < <($GOOGLECL contacts list name,email | grep -v "txt.voice.google.com" | \ | |
sed 's/N\/A//g' | sort -t , -k 1,1 | \ | |
awk -F, '!$1 {a[++i]=$0; next} 1; END {for (j=1; j<=i; j++) print a[j]}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment