Linux join command: Each pair of input lines with the same content is combined into one line
Linux join command Function Description
Use the join command to write to the standard output for each pair of input lines with the same content, combined into one line. The default content join block is the delimiter symbol represented by the first blank character.
When either file 1 or file 2 is specified as -
, the program will read data from the standard input.
Linux join command Syntax
join [option] [file1] [file2]
The meaning of each option in the command is shown in the table:
Option | Description |
---|---|
-a <File Number> |
The value of the file number can be 1 or 2, corresponding to file 1 and file 2 respectively; this option is used to output unpaired lines according to the specified file number |
-e <char> |
Replace the missing input block with the specified word |
-i | Ignore case when comparing |
-j <domain> |
Equivalent to "-1 domain-2 domain" |
-o <format> |
Construct output lines in the specified format |
-t <char> |
Use the specified characters as input and output separators |
-v <File Number> |
Similar to -a <File Number> , but prohibits combining output lines |
-1 <domain> |
The combination of this field in file 1 |
-2 <domain> |
This domain combination in file 2 |
--check-order |
Check if the input rows are correctly ordered, even if all input rows are paired |
--nocheck-order |
Does not check if the input is sorted correctly |
Linux join command Demo
In the /root/a1 and /root/a2 files, for each pair of input lines with the same content, they are combined into one line and written to the standard output.
[root@rhel ~]# cat /root/a1
a
c
[root@rhel ~]# cat /root/a2
a
b
[root@rhel ~]# join /root/a1 /root/a2
a
in apidemos.com.sort.txt and apidemos.com.txt files,for each pair of input lines with the same content, they are combined into one line and written to the standard output.
join /root/apidemos.com.sort.txt /root/apidemos.com.txt
Output: