1. Command function
join merges each pair of input lines with the same content into a single line of output. By default, the first field of the input is used as the connection field, and the fields are separated by spaces.
2. Grammar format
join option file1 file2
join options file 1 file 2
Parameter Description
parameter |
Parameter Description |
-a file number |
Unmatched lines in the output file, the file number can be 1 or 2, 1 represents file 1, 2 represents file 2 |
-i |
Compare fields ignore case |
-1 field |
Process merge based on the specified fields of the first file |
-2 fields |
Process merge based on the specified fields of the 2nd file |
3. Example of use
Example 1 Merge files
[root@localhost ~]# cat a.txt Wang Xiaoxue is 23 years old Li Xue is 21 years old little stone 8 years old Wang Dachui is 30 years old [root@localhost ~]# cat b.txt king sledgehammer Li Xuenv King two hair man [root@localhost ~]# join a.txt b.txt join: file 1 is not sorted correctly [root@localhost ~]# sort a.txt > a.txt_1 <---- sort a.txt [root@localhost ~]# join a.txt_1 b.txt join: file 2 is not sorted correctly Wang Dachui's 30-year-old male [root@localhost ~]# sort b.txt > b.txt_2 <---- sort b.txt [root@localhost ~]# join a.txt_1 b.txt_2 Li Xue, 21-year-old female Wang Dachui's 30-year-old male