join

merges two files on a common field

TLDR

Join on first field
$ join [file1] [file2]
Join on specific fields
$ join -1 [2] -2 [1] [file1] [file2]
Output specific fields
$ join -o 1.1,2.2 [file1] [file2]
Case insensitive
$ join -i [file1] [file2]
Show unmatched lines
$ join -a 1 [file1] [file2]
Custom delimiter
$ join -t "," [file1.csv] [file2.csv]

SYNOPSIS

join [options] file1 file2

DESCRIPTION

join merges two files on a common field. It performs relational database-style joins on text files.Files must be sorted on the join field. The tool supports inner, left, and right join operations.

PARAMETERS

FILE1 FILE2

Files to join (must be sorted on join field).
-1 FIELD
Join on field N of file 1.
-2 FIELD
Join on field N of file 2.
-o FORMAT
Output format specification.
-t CHAR
Field delimiter.
-i
Ignore case differences.
-a FILENUM
Print unpairable lines.
--help
Display help information.

INSTALL

sudo apt install coreutils
sudo dnf install coreutils
sudo pacman -S coreutils
sudo apk add coreutils
sudo zypper install coreutils
brew install coreutils
nix profile install nixpkgs#coreutils

CAVEATS

Files must be sorted. Field-based joining. Default whitespace delimiter.

HISTORY

join is part of POSIX and traditional Unix utilities, providing relational join operations on text files.

SEE ALSO

sort(1), cut(1), paste(1), awk(1)