SHELL脚本自动转换Excel为通讯录vcf文件

办公日常 Liemer_Lius 379℃

1、Excel收集联系人信息

Excel表格样式:

姓名 部门 手机 邮箱 职位 上级
诸葛亮 战略规划与实施部 18511001100 zgl@sanguo.com 策划总监 刘备

其中,表头去掉即可,收集所有的联系人信息到一个表格,复制除表头的内容到contact.txt

2、编辑脚本

# cat mk.sh 
#!/bin/bash

function mk_QUOTED() {
    tr -d '\n' |od -An -tx1 |tr ' ' = |tr 'a-z' 'A-Z' |tr -d '\n'
}

> contact.vcf
cat contact.txt |while read CON_LINE; do
    NAME=$( echo ${CON_LINE} |awk '{printf "%s-%s", $1,$2}' |mk_QUOTED )
    ORG=$( echo ${CON_LINE} |awk '{print $2}' |mk_QUOTED )
    PHONE=$( echo ${CON_LINE} |awk '{print $3}' )
    EMAIL=$( echo ${CON_LINE} |awk '{print $4}' )
    TITLE=$( echo ${CON_LINE} |awk '{print $5}' |mk_QUOTED )
    SUPER=$( echo ${CON_LINE} |awk '{print $6}' |mk_QUOTED )
    cat << EOF >> contact.vcf
BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;${NAME};;;
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:${NAME}
TEL;CELL:${PHONE}
EMAIL;WORK:${EMAIL}
TITLE;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:${TITLE}
X-ANDROID-CUSTOM;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:vnd.android.cursor.item/relation;${SUPER};=37;;;;;;;;;;;;;
X-GROUP-MEMBERSHIP:三国蜀国
END:VCARD
EOF
done

其中,姓名、组织、职务都是QUOTED-PRINTABLE编码[mk_QUOTED函数转换],Email、电话、分组[三国蜀国]是明文的。

3、执行脚本生成vcf文件,联系人导入即可

BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:;=E8=AF=B8=E8=91=9B=E4=BA=AE=2D=E6=88=98=E7=95=A5=E8=A7=84=E5=88=92=E4=B8=8E=E5=AE=9E=E6=96=BD=E9=83=A8;;;
FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E8=AF=B8=E8=91=9B=E4=BA=AE=2D=E6=88=98=E7=95=A5=E8=A7=84=E5=88=92=E4=B8=8E=E5=AE=9E=E6=96=BD=E9=83=A8
TEL;CELL:18511001100
EMAIL;WORK:zgl@sanguo.com
TITLE;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=E7=AD=96=E5=88=92=E6=80=BB=E7=9B=91
X-ANDROID-CUSTOM;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:vnd.android.cursor.item/relation;=E5=88=98=E5=A4=87;=37;;;;;;;;;;;;;
X-GROUP-MEMBERSHIP:三国蜀国
END:VCARD

4、效果

转载请注明:liutianfeng.com » SHELL脚本自动转换Excel为通讯录vcf文件

喜欢 (2)

评论已关闭。