Latest web development tutorials

Linux join command

Linux command Daquan Linux command Daquan

Linux join command for both files in the same line specifies the contents of the field are connected.

Identify the two documents in the same line specifies the contents of the field, and to be merged, and then output to the standard output device.

grammar

join [-i][-a<1或2>][-e<字符串>][-o<格式>][-t<字符>][-v<1或2>][-1<栏位>][-2<栏位>][--help][--version][文件1][文件2]

Parameters:

  • -a <1 or 2> In addition to showing the contents of the original output, but also the display instruction file does not contain the same field line.
  • -e <string> If [file 1] [file 2] not found in the specified field, the options to fill in the output string.
  • -i or --igore-case comparison of field content, ignoring case differences.
  • -o <Format> in the specified format to display the results.
  • -t <character> Use field delimiter character.
  • -v <1 or 2> -a with the same, but the file does not show only the same field line.
  • -1 <Field> Connection [file 1] specified fields.
  • -2 <Field> Connection [Document 2] specified fields.
  • --help displays help.
  • --version display version information.

Examples

Connect the two files.

In order to clearly understand the join command displays the contents of the first file testfile_1 and testfile_2 by the cat command.

Then the default method to compare two files, the same file in two lines connecting the specified field, enter the command in a terminal:

join testfile_1 testfile_2 

First check testfile_1, testfile_2 contents of the file:

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

Then use the command to join the two documents connected with the following results:

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

File 1 and File 2 position output to standard output is the result of an impact. For example, two command file interchange that enter the following command:

join testfile_2 testfile_1

Final output in standard output will change as follows:

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

Linux command Daquan Linux command Daquan