Name
join
Synopsis
join [options
]file1 file2
Join the common lines of sorted file1
and sorted file2. Read standard input if
file1 is -
. The output
contains the common field and the remainder of each line from
file1 and file2. In the
options below, n can be 1 or 2, referring to
file1 or file2.
Common Options
-
-a
filenum
List unpairable lines in file filenum. Use
-a 1 -a 2
to list unpairable lines from both files.-
-e
string
Replace any empty output field with the string string.
-
-o
n.m
Each output line contains fields specified by file number n and field number m. The common field is suppressed unless requested.
-
-t
c
Use character c as field separator for input and output.
-
-v
n
Print only the unpairable lines in file n. With both
-v 1
and-v 2
, all unpairable lines are printed.-
-1
m
Join on field m of file 1. Fields start with 1.
-
-2
m
Join on field m of file 2. Fields start with 1.
Solaris and GNU/Linux Option
-
-j
fieldnum
Equivalent to
-1
fieldnum
-2
fieldnum
.
Solaris Options
-
-j1
fieldnum
Equivalent to
-1
fieldnum
.-
-j2
fieldnum
Equivalent to
-2
fieldnum
.
GNU/Linux Option
-i
,--ignore-case
Ignore case differences when comparing keys.
Examples
Assuming the following input files:
$cat score
olga 81 91 rene 82 92 zack 83 93 $cat grade
olga B A rene B A
List scores followed by grades, including unmatched lines:
$ join -a1 score grade
olga 81 91 B A
rene 82 92 B A
zack 83 93
Pair each score with its grade:
$ join -o 1.1 1.2 2.2 1.3 2.3 score grade
olga 81 B 91 A
rene 82 B 92 A
Get Unix in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.