1*6e0ed9c9SLionel Sambuc.\" $NetBSD: join.1,v 1.13 2012/04/08 22:00:39 wiz Exp $ 2*6e0ed9c9SLionel Sambuc.\" 3*6e0ed9c9SLionel Sambuc.\" Copyright (c) 1990, 1993 4*6e0ed9c9SLionel Sambuc.\" The Regents of the University of California. All rights reserved. 5*6e0ed9c9SLionel Sambuc.\" 6*6e0ed9c9SLionel Sambuc.\" This code is derived from software contributed to Berkeley by 7*6e0ed9c9SLionel Sambuc.\" the Institute of Electrical and Electronics Engineers, Inc. 8*6e0ed9c9SLionel Sambuc.\" 9*6e0ed9c9SLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 10*6e0ed9c9SLionel Sambuc.\" modification, are permitted provided that the following conditions 11*6e0ed9c9SLionel Sambuc.\" are met: 12*6e0ed9c9SLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 13*6e0ed9c9SLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 14*6e0ed9c9SLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 15*6e0ed9c9SLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 16*6e0ed9c9SLionel Sambuc.\" documentation and/or other materials provided with the distribution. 17*6e0ed9c9SLionel Sambuc.\" 3. Neither the name of the University nor the names of its contributors 18*6e0ed9c9SLionel Sambuc.\" may be used to endorse or promote products derived from this software 19*6e0ed9c9SLionel Sambuc.\" without specific prior written permission. 20*6e0ed9c9SLionel Sambuc.\" 21*6e0ed9c9SLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22*6e0ed9c9SLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23*6e0ed9c9SLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24*6e0ed9c9SLionel Sambuc.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25*6e0ed9c9SLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26*6e0ed9c9SLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27*6e0ed9c9SLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28*6e0ed9c9SLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29*6e0ed9c9SLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30*6e0ed9c9SLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*6e0ed9c9SLionel Sambuc.\" SUCH DAMAGE. 32*6e0ed9c9SLionel Sambuc.\" 33*6e0ed9c9SLionel Sambuc.\" from: @(#)join.1 8.3 (Berkeley) 4/28/95 34*6e0ed9c9SLionel Sambuc.\" $NetBSD: join.1,v 1.13 2012/04/08 22:00:39 wiz Exp $ 35*6e0ed9c9SLionel Sambuc.\" 36*6e0ed9c9SLionel Sambuc.Dd April 28, 1995 37*6e0ed9c9SLionel Sambuc.Dt JOIN 1 38*6e0ed9c9SLionel Sambuc.Os 39*6e0ed9c9SLionel Sambuc.Sh NAME 40*6e0ed9c9SLionel Sambuc.Nm join 41*6e0ed9c9SLionel Sambuc.Nd relational database operator 42*6e0ed9c9SLionel Sambuc.Sh SYNOPSIS 43*6e0ed9c9SLionel Sambuc.Nm 44*6e0ed9c9SLionel Sambuc.Op Fl a Ar file_number | Fl v Ar file_number 45*6e0ed9c9SLionel Sambuc.Op Fl e Ar string 46*6e0ed9c9SLionel Sambuc.Op Fl j Ar file_number field 47*6e0ed9c9SLionel Sambuc.Op Fl o Ar list 48*6e0ed9c9SLionel Sambuc.Op Fl t Ar char 49*6e0ed9c9SLionel Sambuc.Op Fl \&1 Ar field 50*6e0ed9c9SLionel Sambuc.Op Fl \&2 Ar field 51*6e0ed9c9SLionel Sambuc.Ar file1 file2 52*6e0ed9c9SLionel Sambuc.Sh DESCRIPTION 53*6e0ed9c9SLionel SambucThe join utility performs an ``equality join'' on the specified files 54*6e0ed9c9SLionel Sambucand writes the result to the standard output. 55*6e0ed9c9SLionel SambucThe ``join field'' is the field in each file by which the files are compared. 56*6e0ed9c9SLionel SambucThe first field in each line is used by default. 57*6e0ed9c9SLionel SambucThere is one line in the output for each pair of lines in 58*6e0ed9c9SLionel Sambuc.Ar file1 59*6e0ed9c9SLionel Sambucand 60*6e0ed9c9SLionel Sambuc.Ar file2 61*6e0ed9c9SLionel Sambucwhich have identical join fields. 62*6e0ed9c9SLionel SambucEach output line consists of the join field, the remaining fields from 63*6e0ed9c9SLionel Sambuc.Ar file1 64*6e0ed9c9SLionel Sambucand then the remaining fields from 65*6e0ed9c9SLionel Sambuc.Ar file2 . 66*6e0ed9c9SLionel Sambuc.Pp 67*6e0ed9c9SLionel SambucThe default field separators are tab and space characters. 68*6e0ed9c9SLionel SambucIn this case, multiple tabs and spaces count as a single field separator, 69*6e0ed9c9SLionel Sambucand leading tabs and spaces are ignored. 70*6e0ed9c9SLionel SambucThe default output field separator is a single space character. 71*6e0ed9c9SLionel Sambuc.Pp 72*6e0ed9c9SLionel SambucMany of the options use file and field numbers. 73*6e0ed9c9SLionel SambucBoth file numbers and field numbers are 1 based, i.e. the first file on 74*6e0ed9c9SLionel Sambucthe command line is file number 1 and the first field is field number 1. 75*6e0ed9c9SLionel SambucThe following options are available: 76*6e0ed9c9SLionel Sambuc.Bl -tag -width Fl 77*6e0ed9c9SLionel Sambuc.It Fl a Ar file_number 78*6e0ed9c9SLionel SambucIn addition to the default output, produce a line for each unpairable 79*6e0ed9c9SLionel Sambucline in file 80*6e0ed9c9SLionel Sambuc.Ar file_number . 81*6e0ed9c9SLionel Sambuc(The argument to 82*6e0ed9c9SLionel Sambuc.Fl a 83*6e0ed9c9SLionel Sambucmust not be preceded by a space; see the 84*6e0ed9c9SLionel Sambuc.Sx COMPATIBILITY 85*6e0ed9c9SLionel Sambucsection.) 86*6e0ed9c9SLionel Sambuc.It Fl e Ar string 87*6e0ed9c9SLionel SambucReplace empty output fields with 88*6e0ed9c9SLionel Sambuc.Ar string . 89*6e0ed9c9SLionel Sambuc.It Fl o Ar list 90*6e0ed9c9SLionel SambucThe 91*6e0ed9c9SLionel Sambuc.Fl o 92*6e0ed9c9SLionel Sambucoption specifies the fields that will be output from each file for 93*6e0ed9c9SLionel Sambuceach line with matching join fields. 94*6e0ed9c9SLionel SambucEach element of 95*6e0ed9c9SLionel Sambuc.Ar list 96*6e0ed9c9SLionel Sambuchas the form 97*6e0ed9c9SLionel Sambuc.Ql file_number.field , 98*6e0ed9c9SLionel Sambucwhere 99*6e0ed9c9SLionel Sambuc.Ar file_number 100*6e0ed9c9SLionel Sambucis a file number and 101*6e0ed9c9SLionel Sambuc.Ar field 102*6e0ed9c9SLionel Sambucis a field number. 103*6e0ed9c9SLionel SambucThe elements of list must be either comma (``,'') or whitespace separated. 104*6e0ed9c9SLionel Sambuc(The latter requires quoting to protect it from the shell, or, a simpler 105*6e0ed9c9SLionel Sambucapproach is to use multiple 106*6e0ed9c9SLionel Sambuc.Fl o 107*6e0ed9c9SLionel Sambucoptions.) 108*6e0ed9c9SLionel Sambuc.It Fl t Ar char 109*6e0ed9c9SLionel SambucUse character 110*6e0ed9c9SLionel Sambuc.Ar char 111*6e0ed9c9SLionel Sambucas a field delimiter for both input and output. 112*6e0ed9c9SLionel SambucEvery occurrence of 113*6e0ed9c9SLionel Sambuc.Ar char 114*6e0ed9c9SLionel Sambucin a line is significant. 115*6e0ed9c9SLionel Sambuc.It Fl v Ar file_number 116*6e0ed9c9SLionel SambucDo not display the default output, but display a line for each unpairable 117*6e0ed9c9SLionel Sambucline in file 118*6e0ed9c9SLionel Sambuc.Ar file_number . 119*6e0ed9c9SLionel SambucThe options 120*6e0ed9c9SLionel Sambuc.Fl v Ar 1 121*6e0ed9c9SLionel Sambucand 122*6e0ed9c9SLionel Sambuc.Fl v Ar 2 123*6e0ed9c9SLionel Sambucmay be specified at the same time. 124*6e0ed9c9SLionel Sambuc.It Fl 1 Ar field 125*6e0ed9c9SLionel SambucJoin on the 126*6e0ed9c9SLionel Sambuc.Ar field Ns 'th 127*6e0ed9c9SLionel Sambucfield of file 1. 128*6e0ed9c9SLionel Sambuc.It Fl 2 Ar field 129*6e0ed9c9SLionel SambucJoin on the 130*6e0ed9c9SLionel Sambuc.Ar field Ns 'th 131*6e0ed9c9SLionel Sambucfield of file 2. 132*6e0ed9c9SLionel Sambuc.El 133*6e0ed9c9SLionel Sambuc.Pp 134*6e0ed9c9SLionel SambucWhen the default field delimiter characters are used, the files to be joined 135*6e0ed9c9SLionel Sambucshould be ordered in the collating sequence of 136*6e0ed9c9SLionel Sambuc.Xr sort 1 , 137*6e0ed9c9SLionel Sambucusing the 138*6e0ed9c9SLionel Sambuc.Fl b 139*6e0ed9c9SLionel Sambucoption, on the fields on which they are to be joined, otherwise 140*6e0ed9c9SLionel Sambuc.Nm 141*6e0ed9c9SLionel Sambucmay not report all field matches. 142*6e0ed9c9SLionel SambucWhen the field delimiter characters are specified by the 143*6e0ed9c9SLionel Sambuc.Fl t 144*6e0ed9c9SLionel Sambucoption, the collating sequence should be the same as 145*6e0ed9c9SLionel Sambuc.Xr sort 1 146*6e0ed9c9SLionel Sambucwithout the 147*6e0ed9c9SLionel Sambuc.Fl b 148*6e0ed9c9SLionel Sambucoption. 149*6e0ed9c9SLionel Sambuc.Pp 150*6e0ed9c9SLionel SambucIf one of the arguments 151*6e0ed9c9SLionel Sambuc.Ar file1 152*6e0ed9c9SLionel Sambucor 153*6e0ed9c9SLionel Sambuc.Ar file2 154*6e0ed9c9SLionel Sambucis ``-'', the standard input is used. 155*6e0ed9c9SLionel Sambuc.Pp 156*6e0ed9c9SLionel SambucThe 157*6e0ed9c9SLionel Sambuc.Nm 158*6e0ed9c9SLionel Sambucutility exits 0 on success, and \*[Gt]0 if an error occurs. 159*6e0ed9c9SLionel Sambuc.Sh COMPATIBILITY 160*6e0ed9c9SLionel SambucFor compatibility with historic versions of 161*6e0ed9c9SLionel Sambuc.Nm , 162*6e0ed9c9SLionel Sambucthe following options are available: 163*6e0ed9c9SLionel Sambuc.Bl -tag -width Fl 164*6e0ed9c9SLionel Sambuc.It Fl a 165*6e0ed9c9SLionel SambucIn addition to the default output, produce a line for each unpairable line 166*6e0ed9c9SLionel Sambucin both file 1 and file 2. 167*6e0ed9c9SLionel Sambuc(To distinguish between this and 168*6e0ed9c9SLionel Sambuc.Fl a Ar file_number , 169*6e0ed9c9SLionel Sambuc.Nm 170*6e0ed9c9SLionel Sambuccurrently requires that the latter not include any white space.) 171*6e0ed9c9SLionel Sambuc.It Fl j1 Ar field 172*6e0ed9c9SLionel SambucJoin on the 173*6e0ed9c9SLionel Sambuc.Ar field Ns 'th 174*6e0ed9c9SLionel Sambucfield of file 1. 175*6e0ed9c9SLionel Sambuc.It Fl j2 Ar field 176*6e0ed9c9SLionel SambucJoin on the 177*6e0ed9c9SLionel Sambuc.Ar field Ns 'th 178*6e0ed9c9SLionel Sambucfield of file 2. 179*6e0ed9c9SLionel Sambuc.It Fl j Ar field 180*6e0ed9c9SLionel SambucJoin on the 181*6e0ed9c9SLionel Sambuc.Ar field Ns 'th 182*6e0ed9c9SLionel Sambucfield of both file 1 and file 2. 183*6e0ed9c9SLionel Sambuc.It Fl o Ar list ... 184*6e0ed9c9SLionel SambucHistorical implementations of 185*6e0ed9c9SLionel Sambuc.Nm 186*6e0ed9c9SLionel Sambucpermitted multiple arguments to the 187*6e0ed9c9SLionel Sambuc.Fl o 188*6e0ed9c9SLionel Sambucoption. 189*6e0ed9c9SLionel SambucThese arguments were of the form ``file_number.field_number'' as described 190*6e0ed9c9SLionel Sambucfor the current 191*6e0ed9c9SLionel Sambuc.Fl o 192*6e0ed9c9SLionel Sambucoption. 193*6e0ed9c9SLionel SambucThis has obvious difficulties in the presence of files named ``1.2''. 194*6e0ed9c9SLionel Sambuc.El 195*6e0ed9c9SLionel Sambuc.Pp 196*6e0ed9c9SLionel SambucThese options are available only so historic shell scripts don't require 197*6e0ed9c9SLionel Sambucmodification and should not be used. 198*6e0ed9c9SLionel Sambuc.Sh SEE ALSO 199*6e0ed9c9SLionel Sambuc.Xr awk 1 , 200*6e0ed9c9SLionel Sambuc.Xr comm 1 , 201*6e0ed9c9SLionel Sambuc.Xr paste 1 , 202*6e0ed9c9SLionel Sambuc.Xr sort 1 , 203*6e0ed9c9SLionel Sambuc.Xr uniq 1 204*6e0ed9c9SLionel Sambuc.Sh STANDARDS 205*6e0ed9c9SLionel SambucThe 206*6e0ed9c9SLionel Sambuc.Nm 207*6e0ed9c9SLionel Sambuccommand is expected to be 208*6e0ed9c9SLionel Sambuc.St -p1003.2 209*6e0ed9c9SLionel Sambuccompatible. 210