1*40396b53Swiz.\" $NetBSD: join.1,v 1.15 2017/07/04 07:01:53 wiz Exp $ 220d49058Stls.\" 320d49058Stls.\" Copyright (c) 1990, 1993 420d49058Stls.\" The Regents of the University of California. All rights reserved. 5f7d7921aSglass.\" 6f7d7921aSglass.\" This code is derived from software contributed to Berkeley by 7f7d7921aSglass.\" the Institute of Electrical and Electronics Engineers, Inc. 8f7d7921aSglass.\" 9f7d7921aSglass.\" Redistribution and use in source and binary forms, with or without 10f7d7921aSglass.\" modification, are permitted provided that the following conditions 11f7d7921aSglass.\" are met: 12f7d7921aSglass.\" 1. Redistributions of source code must retain the above copyright 13f7d7921aSglass.\" notice, this list of conditions and the following disclaimer. 14f7d7921aSglass.\" 2. Redistributions in binary form must reproduce the above copyright 15f7d7921aSglass.\" notice, this list of conditions and the following disclaimer in the 16f7d7921aSglass.\" documentation and/or other materials provided with the distribution. 1789aaa1bbSagc.\" 3. Neither the name of the University nor the names of its contributors 18f7d7921aSglass.\" may be used to endorse or promote products derived from this software 19f7d7921aSglass.\" without specific prior written permission. 20f7d7921aSglass.\" 21f7d7921aSglass.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22f7d7921aSglass.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23f7d7921aSglass.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24f7d7921aSglass.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25f7d7921aSglass.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26f7d7921aSglass.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27f7d7921aSglass.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28f7d7921aSglass.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29f7d7921aSglass.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30f7d7921aSglass.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31f7d7921aSglass.\" SUCH DAMAGE. 32f7d7921aSglass.\" 3320d49058Stls.\" from: @(#)join.1 8.3 (Berkeley) 4/28/95 34f7d7921aSglass.\" 3520d49058Stls.Dd April 28, 1995 36f7d7921aSglass.Dt JOIN 1 37f7d7921aSglass.Os 38f7d7921aSglass.Sh NAME 39f7d7921aSglass.Nm join 40f7d7921aSglass.Nd relational database operator 41f7d7921aSglass.Sh SYNOPSIS 42990562bfSwiz.Nm 431ac719d1Swiz.Op Fl a Ar file_number | Fl v Ar file_number 44a1c657feSmycroft.Op Fl e Ar string 45a1c657feSmycroft.Op Fl j Ar file_number field 46a1c657feSmycroft.Op Fl o Ar list 47f7d7921aSglass.Op Fl t Ar char 48f7d7921aSglass.Op Fl \&1 Ar field 49f7d7921aSglass.Op Fl \&2 Ar field 50a1c657feSmycroft.Ar file1 file2 51f7d7921aSglass.Sh DESCRIPTION 52f7d7921aSglassThe join utility performs an ``equality join'' on the specified files 53f7d7921aSglassand writes the result to the standard output. 54f7d7921aSglassThe ``join field'' is the field in each file by which the files are compared. 55f7d7921aSglassThe first field in each line is used by default. 56f7d7921aSglassThere is one line in the output for each pair of lines in 57f7d7921aSglass.Ar file1 58f7d7921aSglassand 59f7d7921aSglass.Ar file2 60f7d7921aSglasswhich have identical join fields. 61f7d7921aSglassEach output line consists of the join field, the remaining fields from 62f7d7921aSglass.Ar file1 63f7d7921aSglassand then the remaining fields from 64f7d7921aSglass.Ar file2 . 65f7d7921aSglass.Pp 66f7d7921aSglassThe default field separators are tab and space characters. 67f7d7921aSglassIn this case, multiple tabs and spaces count as a single field separator, 68f7d7921aSglassand leading tabs and spaces are ignored. 69f7d7921aSglassThe default output field separator is a single space character. 70f7d7921aSglass.Pp 71f7d7921aSglassMany of the options use file and field numbers. 72f7d7921aSglassBoth file numbers and field numbers are 1 based, i.e. the first file on 73f7d7921aSglassthe command line is file number 1 and the first field is field number 1. 74f7d7921aSglassThe following options are available: 75f7d7921aSglass.Bl -tag -width Fl 76f7d7921aSglass.It Fl a Ar file_number 77f7d7921aSglassIn addition to the default output, produce a line for each unpairable 78f7d7921aSglassline in file 79f7d7921aSglass.Ar file_number . 8020d49058Stls(The argument to 8120d49058Stls.Fl a 8220d49058Stlsmust not be preceded by a space; see the 8320d49058Stls.Sx COMPATIBILITY 8420d49058Stlssection.) 85f7d7921aSglass.It Fl e Ar string 86f7d7921aSglassReplace empty output fields with 87f7d7921aSglass.Ar string . 88f7d7921aSglass.It Fl o Ar list 89f7d7921aSglassThe 90f7d7921aSglass.Fl o 91f7d7921aSglassoption specifies the fields that will be output from each file for 92f7d7921aSglasseach line with matching join fields. 93f7d7921aSglassEach element of 94f7d7921aSglass.Ar list 95f7d7921aSglasshas the form 96f7d7921aSglass.Ql file_number.field , 97f7d7921aSglasswhere 98f7d7921aSglass.Ar file_number 99f7d7921aSglassis a file number and 100f7d7921aSglass.Ar field 101f7d7921aSglassis a field number. 102f7d7921aSglassThe elements of list must be either comma (``,'') or whitespace separated. 10320d49058Stls(The latter requires quoting to protect it from the shell, or, a simpler 104f7d7921aSglassapproach is to use multiple 105f7d7921aSglass.Fl o 106f7d7921aSglassoptions.) 107f7d7921aSglass.It Fl t Ar char 108f7d7921aSglassUse character 109f7d7921aSglass.Ar char 110f7d7921aSglassas a field delimiter for both input and output. 111f7d7921aSglassEvery occurrence of 112f7d7921aSglass.Ar char 113f7d7921aSglassin a line is significant. 114f7d7921aSglass.It Fl v Ar file_number 115f7d7921aSglassDo not display the default output, but display a line for each unpairable 116f7d7921aSglassline in file 117f7d7921aSglass.Ar file_number . 118f7d7921aSglassThe options 119f7d7921aSglass.Fl v Ar 1 120f7d7921aSglassand 121f7d7921aSglass.Fl v Ar 2 122f7d7921aSglassmay be specified at the same time. 123f7d7921aSglass.It Fl 1 Ar field 124f7d7921aSglassJoin on the 125f7d7921aSglass.Ar field Ns 'th 126f7d7921aSglassfield of file 1. 127f7d7921aSglass.It Fl 2 Ar field 128f7d7921aSglassJoin on the 129f7d7921aSglass.Ar field Ns 'th 130f7d7921aSglassfield of file 2. 131f7d7921aSglass.El 132f7d7921aSglass.Pp 133f7d7921aSglassWhen the default field delimiter characters are used, the files to be joined 134f7d7921aSglassshould be ordered in the collating sequence of 135f7d7921aSglass.Xr sort 1 , 136f7d7921aSglassusing the 137f7d7921aSglass.Fl b 138f7d7921aSglassoption, on the fields on which they are to be joined, otherwise 139ac4e9aa7Slukem.Nm 140f7d7921aSglassmay not report all field matches. 141f7d7921aSglassWhen the field delimiter characters are specified by the 142f7d7921aSglass.Fl t 143f7d7921aSglassoption, the collating sequence should be the same as 144c4aebac5Swiz.Xr sort 1 145f7d7921aSglasswithout the 146f7d7921aSglass.Fl b 147f7d7921aSglassoption. 148f7d7921aSglass.Pp 149f7d7921aSglassIf one of the arguments 150f7d7921aSglass.Ar file1 151f7d7921aSglassor 152f7d7921aSglass.Ar file2 153f7d7921aSglassis ``-'', the standard input is used. 154*40396b53Swiz.Sh EXIT STATUS 155*40396b53Swiz.Ex -std join 156f7d7921aSglass.Sh COMPATIBILITY 157f7d7921aSglassFor compatibility with historic versions of 158990562bfSwiz.Nm , 159f7d7921aSglassthe following options are available: 160f7d7921aSglass.Bl -tag -width Fl 161f7d7921aSglass.It Fl a 162f7d7921aSglassIn addition to the default output, produce a line for each unpairable line 163f7d7921aSglassin both file 1 and file 2. 16420d49058Stls(To distinguish between this and 16520d49058Stls.Fl a Ar file_number , 166ac4e9aa7Slukem.Nm 16720d49058Stlscurrently requires that the latter not include any white space.) 168f7d7921aSglass.It Fl j1 Ar field 169f7d7921aSglassJoin on the 170f7d7921aSglass.Ar field Ns 'th 171f7d7921aSglassfield of file 1. 172f7d7921aSglass.It Fl j2 Ar field 173f7d7921aSglassJoin on the 174f7d7921aSglass.Ar field Ns 'th 175f7d7921aSglassfield of file 2. 176f7d7921aSglass.It Fl j Ar field 177f7d7921aSglassJoin on the 178f7d7921aSglass.Ar field Ns 'th 179f7d7921aSglassfield of both file 1 and file 2. 180f7d7921aSglass.It Fl o Ar list ... 181f7d7921aSglassHistorical implementations of 182ac4e9aa7Slukem.Nm 183f7d7921aSglasspermitted multiple arguments to the 184f7d7921aSglass.Fl o 185f7d7921aSglassoption. 186f7d7921aSglassThese arguments were of the form ``file_number.field_number'' as described 187f7d7921aSglassfor the current 188f7d7921aSglass.Fl o 189f7d7921aSglassoption. 190f7d7921aSglassThis has obvious difficulties in the presence of files named ``1.2''. 191f7d7921aSglass.El 192f7d7921aSglass.Pp 193f7d7921aSglassThese options are available only so historic shell scripts don't require 194f7d7921aSglassmodification and should not be used. 195f7d7921aSglass.Sh SEE ALSO 196f7d7921aSglass.Xr awk 1 , 197f7d7921aSglass.Xr comm 1 , 198f7d7921aSglass.Xr paste 1 , 199f7d7921aSglass.Xr sort 1 , 200f7d7921aSglass.Xr uniq 1 201cb292d0dSwiz.Sh STANDARDS 202cb292d0dSwizThe 203cb292d0dSwiz.Nm 204cb292d0dSwizcommand is expected to be 205cb292d0dSwiz.St -p1003.2 206cb292d0dSwizcompatible. 207