Join lines of two files on a common field.
Synopsis
join [OPTION]... FILE1 FILE2
Description
For each pair of input lines with identical join fields, writes a line to standard output. The default join field is the first, delimited by blanks.
Options
-1 FIELD Join on this FIELD of file 1 (default: 1).
-2 FIELD Join on this FIELD of file 2 (default: 1).
-t CHAR Use CHAR as input and output field separator.
-a FILENUM Also print unpairable lines from file FILENUM (1 or 2).
-v FILENUM Like -a but only output unpairable lines.
-e STRING Replace missing fields with STRING.
-o FORMAT Output format (comma-separated list of FILENUM.FIELD).
-i Ignore case when comparing fields.
Examples
$ join file1 file2
Join on the first field of each file.
$ join -1 2 -2 1 file1 file2
Join file1 column 2 with file2 column 1.
$ join -t ',' file1.csv file2.csv
Join CSV files on a comma delimiter.
$ join -a 1 file1 file2
Left outer join.
Notes
Both input files must be sorted on the join field for correct results.
See Also
paste, comm, sort, awk