Linux Comm Join
# Linux join Command
[ Linux Command Reference](#)
The Linux `join` command is used to connect lines from two files where the content of a specified field is the same.
It finds lines in two files where the content of a specified field is the same, merges them, and outputs the result to standard output.
### Syntax
join
**Parameters**:
* -a In addition to displaying the original output, also display lines from the specified file that do not have a matching field.
* -e If the specified field cannot be found in or , fill the output with the string from this option.
* -i or --ignore-case Ignore case differences when comparing field content.
* -o Display the result according to the specified format.
* -t Use the specified character as the field delimiter.
* -v Similar to -a, but only display lines from the file that do not have a matching field.
* -1 Join on the specified field from .
* -2 Join on the specified field from .
* --help Display help information.
* --version Display version information.
### Examples
Joining two files.
To clearly understand the `join` command, first display the contents of files `testfile_1` and `testfile_2` using the `cat` command.
Then, compare the two files in the default manner, joining lines where the content of the specified field is the same. Enter the following command in the terminal:
join testfile_1 testfile_2
First, view the contents of `testfile_1` and `testfile_2`:
$ cat testfile_1 #Content of testfile_1 Hello 95 #For example, in this case, the first column is name, the second is amount Linux 85 test 30 cmd@hdd-desktop:~$ cat testfile_2 #Content of testfile_2 Hello 2005 #For example, in this case, the first column is name, the second is year Linux 2009 test 2006
Then use the `join` command to connect the two files. The result is as follows:
$ join testfile_1 testfile_2 #Connect content from testfile_1 and testfile_2 Hello 95 2005 #Connected content displayed Linux 85 2009 test 30 2006
The position of file1 and file2 affects the output to standard output. For example, swap the two files in the command, i.e., enter the following command:
join testfile_2 testfile_1
The final output to standard output will change, as shown below:
$ join testfile_2 testfile_1 #Swap file order to connect the two files Hello 2005 95 #Connected content displayed Linux 2009 85 test 2006 30
[ Linux Command Reference](#)
YouTip