1.\" Copyright (c) 1990 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the Institute of Electrical and Electronics Engineers, Inc. 6.\" 7.\" %sccs.include.redist.roff% 8.\" 9.\" @(#)join.1 6.7 (Berkeley) 07/29/91 10.\" 11.Dd 12.Dt JOIN 1 13.Os 14.Sh NAME 15.Nm join 16.Nd relational database operator 17.Sh SYNOPSIS 18.Nm join 19.Op Fl a Ar file_number 20.Op Fl e Ar string 21.Op Fl j Ar file_number field 22.Op Fl o Ar list 23.Bk -words 24.Op Fl t Ar char 25.Ek 26.Op Fl v Ar file_number 27.Op Fl \&1 Ar field 28.Op Fl \&2 Ar field 29.Ar file1 30.Ar file2 31.Sh DESCRIPTION 32The join utility performs an ``equality join'' on the files 33.Ar file1 34and 35.Ar file2 . 36The joined files are written to the standard 37output. 38.Pp 39The ``join field'' is a field in each file on which the 40files are compared. 41There is one line in the output for 42each pair of lines in 43.Ar file1 44and 45.Ar file2 46which have identical 47join fields. 48The output line by default consists of the 49join field, then the remaining fields from 50.Ar file1 , 51then the 52remaining fields from 53.Ar file2 . 54This format can be changed by 55using the 56.Fl o 57option (see below). 58.Pp 59The files 60.Ar file1 61and 62.Ar file2 63should be ordered in the collating 64sequence of 65.Ql sort -b 66on the fields on which they are to be 67joined, by default the first in each line; Otherwise, all 68join field matches need not be reported. 69.Pp 70The default input field separators are <blank>s. 71In this 72case, multiple separators count as one field separator, and 73leading separators are ignored. 74The default output field 75separator is a <space>. 76.Pp 77The following options are available: 78.Bl -tag -width Fl 79.It Fl a Ar file_number 80In addition to the default output, produce a line 81for each unpairable line in file 82.Ar file_number , 83where 84.Ar file_number 85is 1 or 2. 86.It Fl e Ar string 87Replace empty output fields by the string 88.Ar string . 89.It Fl j Ar file_number field 90Join on the 91.Ar field Ns 'th 92field of file 93.Ar file_number . 94If 95.Ar file_number 96is missing, (i.e., the 97first digit of the option argument is neither 1 nor 982), use the 99.Ar field Ns 'th 100field in each file. 101Fields are 102decimal integers starting with 1. 103.It Fl o Ar list 104Each output line comprises the fields specified in 105.Ar list , 106each element of which has the form 107.Ql file_number.field , 108where 109.Ar file_number 110is a file 111number and field is a decimal integer field number. 112The elements of list are either comma or <space> separated. 113The list is written only for lines with matching join fields, 114and is not output unless specifically requested. 115.It Fl t Ar char 116Use character 117.Ar char 118as a separator, for both input 119and output. 120Every appearance of char in a line is 121significant. 122When this option is specified, the 123collating sequence should be the same as sort 124without the 125.Fl b 126option. 127.It Fl v Ar file_number 128Instead of the default output, produce a line only 129for each unpairable line in 130.Ar file_number , 131where 132.Ar file_number 133is 1 or 2. 134.It Fl 1 Ar field 135Join on the 136.Ar field Ns 'th 137field of file 1. 138Fields are 139decimal integers starting with 1. 140.It Fl 2 Ar field 141Join on the 142.Ar field Ns 'th 143field of file 2. 144Fields are 145decimal integers starting with 1. 146.El 147.Pp 148If both 149.Ql \-a 1 150and 151.Ql \-a 2 152are specified, both sets of information 153are output, 154.Ql \-a 2 155always first, regardless of the specified 156order. 157.Pp 158The following arguments are required: 159.Bl -tag -width Fl -compact 160.It Ar file1 161.It Ar file2 162A pathname of a file to be joined. 163If either of 164the 165.Ar file1 166or 167.Ar file2 168arguments is 169.Sq Fl 170the standard 171input is used in its place. 172.El 173.Pp 174The 175.Nm join 176utility exits 0 on success, and >0 if an error occurs. 177.Sh STANDARDS 178The 179.Nm join 180command is expected to be 181.St -p1003.2 182compatible. 183.Sh SEE ALSO 184.Xr awk 1 185.Xr comm 1 , 186.Xr look 1 187.Xr sort 1 , 188.Xr uniq 1 , 189.Sh BUGS 190The conventions of 191.Nm join , 192.Xr comm 1 , 193.Xr sort 1 , 194.Xr uniq 1 , 195.Xr look 1 196and 197.Xr awk 1 198are wildly incongruous. 199