Linux uses join a1 to merge the two files


To merge the following two files, merge one in one, into 1.txt

# 1.txt
Jerry 20
Alice 30
David 40
# 2.txt
Jerry man
Alice woman
David 40

The merged 1.txt

[

Jerry 20 man Alice 30 woman David 40

]

The above file features are the same, then merge, column 2 is missing content. join -a1 1.txt 2.txt can be used for this purpose.

[root@host ~]# join -a1 1.txt 2.txt
Jerry 20 man
Alice 30 woman
David 40

-a: Displays all matched lines in the specified file number (1 or 2) in addition to the matched lines -1: Match with FIELD field from file1

conclusion