1.\" $OpenBSD: join.1,v 1.15 2003/12/28 19:53:23 otto Exp $ 2.\" 3.\" Copyright (c) 1990, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" the Institute of Electrical and Electronics Engineers, Inc. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.\" @(#)join.1 8.3 (Berkeley) 4/28/95 34.\" 35.Dd April 28, 1995 36.Dt JOIN 1 37.Os 38.Sh NAME 39.Nm join 40.Nd relational database operator 41.Sh SYNOPSIS 42.Nm join 43.Oo 44.Fl a Ar file_number | Fl v Ar file_number 45.Oc 46.Op Fl e Ar string 47.Op Fl j Ar file_number field 48.Op Fl o Ar list 49.Bk -words 50.Ek 51.Op Fl t Ar char 52.Op Fl \&1 Ar field 53.Op Fl \&2 Ar field 54.Ar file1 55.Ar file2 56.Sh DESCRIPTION 57The 58.Nm 59utility performs an 60.Dq equality join 61on the specified files 62and writes the result to the standard output. 63The 64.Dq join field 65is the field in each file by which the files are compared. 66The first field in each line is used by default. 67There is one line in the output for each pair of lines in 68.Ar file1 69and 70.Ar file2 71which have identical join fields. 72Each output line consists of the join field, the remaining fields from 73.Ar file1 74and then the remaining fields from 75.Ar file2 . 76.Pp 77The default field separators are tab and space characters. 78In this case, multiple tabs and spaces count as a single field separator, 79and leading tabs and spaces are ignored. 80The default output field separator is a single space character. 81.Pp 82Many of the options use file and field numbers. 83Both file numbers and field numbers are 1 based, i.e., the first file on 84the command line is file number 1 and the first field is field number 1. 85.Pp 86The options are as follows: 87.Bl -tag -width Ds 88.It Fl a Ar file_number 89In addition to the default output, produce a line for each unpairable 90line in file 91.Ar file_number . 92.It Fl e Ar string 93Replace empty output fields with 94.Ar string . 95.It Fl o Ar list 96Specifies the fields that will be output from each file for 97each line with matching join fields. 98Each element of 99.Ar list 100has the form 101.Dq file_number.field , 102where 103.Ar file_number 104is a file number and 105.Ar field 106is a field number, 107or the form 108.Dq 0 109(zero), 110representing the join field. 111The elements of list must be either comma 112.Pq Ql \&, 113or whitespace separated. 114(The latter requires quoting to protect it from the shell, or, a simpler 115approach is to use multiple 116.Fl o 117options.) 118.It Fl t Ar char 119Use character 120.Ar char 121as a field delimiter for both input and output. 122Every occurrence of 123.Ar char 124in a line is significant. 125.It Fl v Ar file_number 126Do not display the default output, but display a line for each unpairable 127line in file 128.Ar file_number . 129The options 130.Fl v Ar 1 131and 132.Fl v Ar 2 133may be specified at the same time. 134.It Fl 1 Ar field 135Join on the 136.Ar field Ns 'th 137field of file 1. 138.It Fl 2 Ar field 139Join on the 140.Ar field Ns 'th 141field of file 2. 142.El 143.Pp 144When the default field delimiter characters are used, the files to be joined 145should be ordered in the collating sequence of 146.Xr sort 1 , 147using the 148.Fl b 149option, on the fields on which they are to be joined, otherwise 150.Nm 151may not report all field matches. 152When the field delimiter characters are specified by the 153.Fl t 154option, the collating sequence should be the same as 155.Xr sort 1 156without the 157.Fl b 158option. 159.Pp 160If one of the arguments 161.Ar file1 162or 163.Ar file2 164is 165.Dq - , 166the standard input is used. 167.Pp 168The 169.Nm 170utility exits 0 on success or >0 if an error occurred. 171.Sh SEE ALSO 172.Xr awk 1 , 173.Xr comm 1 , 174.Xr paste 1 , 175.Xr sort 1 , 176.Xr uniq 1 177.Sh STANDARDS 178The 179.Nm 180command is expected to be 181.St -p1003.2 182compatible. 183.Pp 184In the absence of the 185.Fl o 186option, 187historical versions of 188.Nm 189wrote non-matching lines without reordering the fields. 190The current version writes the join field first, followed by the 191remaining fields. 192.Pp 193For compatibility with historical versions of 194.Nm join , 195the following options are available: 196.Bl -tag -width Fl 197.It Fl a 198In addition to the default output, produce a line for each unpairable line 199in both file 1 and file 2. 200.It Fl j1 Ar field 201Join on the 202.Ar field Ns 'th 203field of file 1. 204.It Fl j2 Ar field 205Join on the 206.Ar field Ns 'th 207field of file 2. 208.It Fl j Ar field 209Join on the 210.Ar field Ns 'th 211field of both file 1 and file 2. 212.It Fl o Ar list ... 213Historical implementations of 214.Nm 215permitted multiple arguments to the 216.Fl o 217option. 218These arguments were of the form 219.Dq file_number.field_number 220as described for the current 221.Fl o 222option. 223This has obvious difficulties in the presence of files named 224.Dq 1.2 . 225.El 226.Pp 227These options are available only so historical shell scripts don't require 228modification and should not be used. 229.Sh HISTORY 230A 231.Nm 232utility appeared in 233.At v7 . 234