LinuxCommandLibrary

join

TLDR

Join on first field

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

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.
join merges files on common field.

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.

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)

Copied to clipboard