join

UK[dʒɔɪn] US[dʒɔɪn]

vt.& vi.Join;participate;connect;connect

vt. Participate; combine; get on (train, plane, etc.); get on (road)

n.Connect; combine; join; join point

Third person singular: joins Present participle: joining Past tense : joined past participle: joined

Linux join command syntax

Function: The join command is used to connect lines with the same content in the specified fields in two files.

Syntax: join [-i][-a<1 or 2>][-e<string>][-o<format>][-t<character >][-v<1 or 2>][-1<field>][-2<field>][--help][--version][File1][File2]

Linux join command example

In order to clearly understand the join command, first display the contents of the files testfile_1 and testfile_2 through the cat command.

Then compare the two files in the default way, connect the lines with the same content in the specified fields in the two files, and enter the command in the terminal:

join testfile_1 testfile_2

First check testfile_1 and testfile_2 Contents of the file:

$ cat testfile_1 #testfile_1文件中的内容  Hello 95

#For example, in this example, the first column is the name and the second column is the amount

Linux 85  
test 30  cmd@hdd-desktop:~$ cat testfile_2 #testfile_2文件中的内容  
Hello 2005 #例如,本例中第一列为姓名,第二列为年份  
Linux 2009  
test 2006

Then use the join command to connect the two files. The results are as follows:

$ join testfile_1 testfile_2 #连接testfile_1、testfile_2中的内容  
Hello 
95 
2005 #连接后显示的内容  
Linux 85 2009  
test 30 2006

The locations of file 1 and file 2 have an impact on the results output to standard output. For example, to exchange the two files in the command, enter the following command:

join testfile_2 testfile_1
The final output result on the standard output will change, as follows:

$ join testfile_2 testfile_1 #改变文件顺序连接两个文件  
Hello 2005 95 
#连接后显示的内容  
Linux 2009 85  
test 2006 30