join — Join lines of 2 files on a common fieldSummary:
It will join lines from two files based on a common field which is identical in both files and show the joined line on the screen. By default, join field is the 1st field and space is the default delimiter. The join filed must in sorted order in both files. Output can be saved by redirecting to a file. Example:
$ join f1 f2 -- Join f1 and f2 based on 1st field. $ join -a 1 f1 f2 -- Apart from printing joined line, print the unpairable lines from file 1 alone. $ join -v 2 f1 f2 -- Print only the unpairable lines from file 2. $ join -e "XX" f1 f2 -- In the output, replace the missing inputfield with the string "XX". $ join -i f1 f2 -- Ignore the case, while joining. $ join -j 2 f1 f2 -- Join the files based on the 2nd field in both. $ join -1 2 -2 3 f1 f2 -- Join the files based on the 2nd filed in the 1st file and 3rd field in the 2nd file. $ join -t : f1 f2 -- Fields are delimited by colon char.
Read: man join