#!/system/bin/sh # # reformat_contacts2.db_phone_numbers_to_use_parens # # AUTHOR: # Dan Harkless # # COPYRIGHT: # This file is Copyright (C) 2016 by Dan Harkless, and is released under the # GNU General Public License . # # DESCRIPTION: # The VCF import function in the Android Contacts app reformats (###) ###-#### # phone numbers to ###-###-####, which I find harder to read. If you run this # script on your Android device after the VCF contact list is imported, this # will be fixed (only for U.S.-style 10-digit phone numbers). I recommend # killing the Contacts app first just in case (the Google Contacts Sync # service should be stopped too; I leave it disabled to prevent giving my # contact database to Google, so YMMV if you use it), and root may be # required on some or all devices. # # This script saves your pre-munged contact database as # /data/data/com.android.providers.contacts/databases/contacts2.db.orig. Once # you've checked your contacts after running the script and are happy, you can # delete that file. # # DATE MODIFICATION # ========== ================================================================== # 2016-07-18 Original. cd /data/data/com.android.providers.contacts/databases || exit 1 cp -p contacts2.db-journal contacts2.db-journal.orig cp -p contacts2.db contacts2.db.orig || exit 1 rows=`sqlite3 contacts2.db "SELECT _id, data1 FROM data WHERE mimetype_id=5"` IFS=`echo -e "\n\r"` for row in $rows; do id=`echo "$row" | cut -d'|' -f1` phone=`echo "$row" | cut -d'|' -f2` if echo "$phone" \ | egrep -q "^[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$"; then phone_with_parens="("`echo "$phone" | sed "s/-/) /"` sql="UPDATE data SET data1='$phone_with_parens' WHERE _id=$id" echo "$sql" sqlite3 contacts2.db "$sql" fi done # Running sqlite3 has the side effect of deleting the rollback journal / # exclusive lock file. mv contacts2.db-journal.orig contacts2.db-journal