join命令

join命令可基于两个文件的共同项,把他们合并起来

在下例中,我们有两个文件,分别是employee.txtbonus.txt,他们拥有共同的项– employee-id

所以我们基于employee-id项,将两个文件合并起来。

$ cat employee.txt

100 Jason Smith

200 John Doe

300 Sanjay Gupta

400 Ashok Sharma

 

$ cat bonus.txt

100 $5,000

200 $500

300 $3,000

400 $1,250

 

$ join employee.txt bonus.txt

100 Jason Smith $5,000

200 John Doe $500

300 Sanjay Gupta $3,000

400 Ashok Sharma $1,250