vi TEACHER.db
B Liu:Shanghai Jiaotong University:Shanghai:China
C Lin:University of Toronto:Toronto:Canada
D Hou:Beijing University:Beijing:China
J Luo:Southeast University:NanJing:China
Y Zhang:Victory University:Melbourne:Australia
vi TEACHER_HOBBY.db
B Liu:Tea
C Lin:Song
J Cao:Pingpong
Q Cai:Shoping
Y Zhang:Photography
Z Wu:Chess
join -t: TEACHER.db TEACHER_HOBBY.db -t将域改为分隔符冒号
B Liu:Shanghai Jiaotong University:Shanghai:China:Tea
C Lin:University of Toronto:Toronto:Canada:Song
Y Zhang:Victory University:Melbourne:Australia:Photography
join -t: -a1 TEACHER.db TEACHER_HOBBY.db #-a1表示还显示第一个文件中没有共同域的记录,
#-a2则表示第二个文件中没有共同域的记录
B Liu:Shanghai Jiaotong University:Shanghai:China:Tea
C Lin:University of Toronto:Toronto:Canada:Song
D Hou:Beijing University:Beijing:China
J Luo:Southeast University:NanJing:China
Y Zhang:Victory University:Melbourne:Australia:Photography
join -t: -v1 TEACHER.db TEACHER_HOBBY.db #-v1表示只显示第一个文件中没有共同域的记录,
#-a2表示只显示第二个文件中没有共同域的记录
D Hou:Beijing University:Beijing:China
J Luo:Southeast University:NanJing:China
join -t: -o1.1 2.2 1.2 TEACHER.db TEACHER_HOBBY.db #依次显示第一个文件的第一个域,第二个文件的
#的第二个域,第一个文件的第二个域
B Liu:Tea:Shanghai Jiaotong University
C Lin:Song:University of Toronto
Y Zhang:Photography:Victory University
vi AREACODE.db
BEIJING:86010
HONGKONG:852
SHANGHAI:86021
TORONTO:001416
sort -t: -k3 -o TEACHER1.db TEACHER.db
join -t: -i -1 3 -2 1 TEACHER1.db AREACODE.db #连接文件1的第3域和文件2的第1域,忽略大小写
Beijing:D Hou:Beijing University:China:86010
Shanghai:B Liu:Shanghai Jiaotong University:China:86021
Toronto:C Lin:University of Toronto:Canada:001416
daheng@ubuntu:~/test_program$ cat AREACODE.db
BEIJING:86010
HONGKONG:852
SHANGHAI:86021
TORONTO:001416