xref: /openbsd-src/usr.bin/join/join.1 (revision 940794c79ad91484225a5db735517788b0a01d7c)
1*940794c7Sschwarze.\"	$OpenBSD: join.1,v 1.23 2014/01/19 23:56:06 schwarze Exp $
22e394382Saaron.\"
357441abbSmichaels.\" Copyright (c) 1990, 1993
457441abbSmichaels.\"	The Regents of the University of California.  All rights reserved.
5df930be7Sderaadt.\"
6df930be7Sderaadt.\" This code is derived from software contributed to Berkeley by
7df930be7Sderaadt.\" the Institute of Electrical and Electronics Engineers, Inc.
8df930be7Sderaadt.\"
9df930be7Sderaadt.\" Redistribution and use in source and binary forms, with or without
10df930be7Sderaadt.\" modification, are permitted provided that the following conditions
11df930be7Sderaadt.\" are met:
12df930be7Sderaadt.\" 1. Redistributions of source code must retain the above copyright
13df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer.
14df930be7Sderaadt.\" 2. Redistributions in binary form must reproduce the above copyright
15df930be7Sderaadt.\"    notice, this list of conditions and the following disclaimer in the
16df930be7Sderaadt.\"    documentation and/or other materials provided with the distribution.
17f75387cbSmillert.\" 3. Neither the name of the University nor the names of its contributors
18df930be7Sderaadt.\"    may be used to endorse or promote products derived from this software
19df930be7Sderaadt.\"    without specific prior written permission.
20df930be7Sderaadt.\"
21df930be7Sderaadt.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df930be7Sderaadt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df930be7Sderaadt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df930be7Sderaadt.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df930be7Sderaadt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df930be7Sderaadt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df930be7Sderaadt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df930be7Sderaadt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df930be7Sderaadt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df930be7Sderaadt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df930be7Sderaadt.\" SUCH DAMAGE.
32df930be7Sderaadt.\"
3357441abbSmichaels.\"	@(#)join.1	8.3 (Berkeley) 4/28/95
34df930be7Sderaadt.\"
35*940794c7Sschwarze.Dd $Mdocdate: January 19 2014 $
36df930be7Sderaadt.Dt JOIN 1
37df930be7Sderaadt.Os
38df930be7Sderaadt.Sh NAME
39df930be7Sderaadt.Nm join
40df930be7Sderaadt.Nd relational database operator
41df930be7Sderaadt.Sh SYNOPSIS
42df930be7Sderaadt.Nm join
43e8b5f1bcSjmc.Op Fl 1 Ar field
44e8b5f1bcSjmc.Op Fl 2 Ar field
45df930be7Sderaadt.Oo
46df930be7Sderaadt.Fl a Ar file_number | Fl v Ar file_number
47df930be7Sderaadt.Oc
48df930be7Sderaadt.Op Fl e Ar string
49df930be7Sderaadt.Op Fl o Ar list
50df930be7Sderaadt.Op Fl t Ar char
51df930be7Sderaadt.Ar file1
52df930be7Sderaadt.Ar file2
53df930be7Sderaadt.Sh DESCRIPTION
54581190f2SaaronThe
55581190f2Saaron.Nm
56581190f2Saaronutility performs an
57581190f2Saaron.Dq equality join
58581190f2Saaronon the specified files
59df930be7Sderaadtand writes the result to the standard output.
60581190f2SaaronThe
61581190f2Saaron.Dq join field
62581190f2Saaronis the field in each file by which the files are compared.
63df930be7SderaadtThe first field in each line is used by default.
64df930be7SderaadtThere is one line in the output for each pair of lines in
65df930be7Sderaadt.Ar file1
66df930be7Sderaadtand
67df930be7Sderaadt.Ar file2
68df930be7Sderaadtwhich have identical join fields.
69521d73aaSmillertEach output line consists of the join field, the remaining fields from
70df930be7Sderaadt.Ar file1
71521d73aaSmillertand then the remaining fields from
72df930be7Sderaadt.Ar file2 .
73df930be7Sderaadt.Pp
74df930be7SderaadtThe default field separators are tab and space characters.
75df930be7SderaadtIn this case, multiple tabs and spaces count as a single field separator,
76df930be7Sderaadtand leading tabs and spaces are ignored.
77df930be7SderaadtThe default output field separator is a single space character.
78df930be7Sderaadt.Pp
79df930be7SderaadtMany of the options use file and field numbers.
80581190f2SaaronBoth file numbers and field numbers are 1 based, i.e., the first file on
81df930be7Sderaadtthe command line is file number 1 and the first field is field number 1.
828cf461a5Saaron.Pp
83e8b5f1bcSjmcWhen the default field delimiter characters are used, the files to be joined
84e8b5f1bcSjmcshould be ordered in the collating sequence of
85e8b5f1bcSjmc.Xr sort 1 ,
86e8b5f1bcSjmcusing the
87e8b5f1bcSjmc.Fl b
88e8b5f1bcSjmcoption, on the fields on which they are to be joined, otherwise
89e8b5f1bcSjmc.Nm
90e8b5f1bcSjmcmay not report all field matches.
91e8b5f1bcSjmcWhen the field delimiter characters are specified by the
92e8b5f1bcSjmc.Fl t
93e8b5f1bcSjmcoption, the collating sequence should be the same as
94e8b5f1bcSjmc.Xr sort 1
95e8b5f1bcSjmcwithout the
96e8b5f1bcSjmc.Fl b
97e8b5f1bcSjmcoption.
98e8b5f1bcSjmc.Pp
99e8b5f1bcSjmcIf one of the arguments
100e8b5f1bcSjmc.Ar file1
101e8b5f1bcSjmcor
102e8b5f1bcSjmc.Ar file2
103e8b5f1bcSjmcis
104e8b5f1bcSjmc.Sq - ,
105e8b5f1bcSjmcthe standard input is used.
106e8b5f1bcSjmc.Pp
1078cf461a5SaaronThe options are as follows:
108f1ba3473Saaron.Bl -tag -width Ds
109e8b5f1bcSjmc.It Fl 1 Ar field
110e8b5f1bcSjmcJoin on the
111e8b5f1bcSjmc.Ar field Ns 'th
112e8b5f1bcSjmcfield of
113e8b5f1bcSjmc.Ar file1 .
114e8b5f1bcSjmc.It Fl 2 Ar field
115e8b5f1bcSjmcJoin on the
116e8b5f1bcSjmc.Ar field Ns 'th
117e8b5f1bcSjmcfield of
118e8b5f1bcSjmc.Ar file2 .
119df930be7Sderaadt.It Fl a Ar file_number
120df930be7SderaadtIn addition to the default output, produce a line for each unpairable
121df930be7Sderaadtline in file
122df930be7Sderaadt.Ar file_number .
123df930be7Sderaadt.It Fl e Ar string
124df930be7SderaadtReplace empty output fields with
125df930be7Sderaadt.Ar string .
126df930be7Sderaadt.It Fl o Ar list
127aea1524aSaaronSpecifies the fields that will be output from each file for
128df930be7Sderaadteach line with matching join fields.
129df930be7SderaadtEach element of
130df930be7Sderaadt.Ar list
131df930be7Sderaadthas the form
1322e394382Saaron.Dq file_number.field ,
133df930be7Sderaadtwhere
134df930be7Sderaadt.Ar file_number
135df930be7Sderaadtis a file number and
136df930be7Sderaadt.Ar field
137d697e2c4Sottois a field number,
138d697e2c4Sottoor the form
139d697e2c4Sotto.Dq 0
140d697e2c4Sotto(zero),
141d697e2c4Sottorepresenting the join field.
142581190f2SaaronThe elements of list must be either comma
143581190f2Saaron.Pq Ql \&,
144581190f2Saaronor whitespace separated.
145e8b5f1bcSjmc(The latter requires quoting to protect it from the shell, or a simpler
146df930be7Sderaadtapproach is to use multiple
147df930be7Sderaadt.Fl o
148df930be7Sderaadtoptions.)
149df930be7Sderaadt.It Fl t Ar char
150df930be7SderaadtUse character
151df930be7Sderaadt.Ar char
152df930be7Sderaadtas a field delimiter for both input and output.
153df930be7SderaadtEvery occurrence of
154df930be7Sderaadt.Ar char
155df930be7Sderaadtin a line is significant.
156df930be7Sderaadt.It Fl v Ar file_number
157df930be7SderaadtDo not display the default output, but display a line for each unpairable
158df930be7Sderaadtline in file
159df930be7Sderaadt.Ar file_number .
160df930be7SderaadtThe options
161*940794c7Sschwarze.Fl v Cm 1
162df930be7Sderaadtand
163*940794c7Sschwarze.Fl v Cm 2
164df930be7Sderaadtmay be specified at the same time.
165df930be7Sderaadt.El
166f1c64ac4Sjmc.Sh EXIT STATUS
167e8b5f1bcSjmc.Ex -std join
1683746a816Saaron.Sh SEE ALSO
1693746a816Saaron.Xr awk 1 ,
1703746a816Saaron.Xr comm 1 ,
171123c77e8Shugh.Xr lam 1 ,
1723746a816Saaron.Xr paste 1 ,
1733746a816Saaron.Xr sort 1 ,
1743746a816Saaron.Xr uniq 1
1752aeff9fbSjmc.Sh STANDARDS
1762ccfb32cSottoThe
1772ccfb32cSotto.Nm
1787c5a075bSjmcutility is compliant with the
17999332e38Sjmc.St -p1003.1-2008
1807c5a075bSjmcspecification.
1812ccfb32cSotto.Pp
1822ccfb32cSottoIn the absence of the
1832ccfb32cSotto.Fl o
1842ccfb32cSottooption,
1852ccfb32cSottohistorical versions of
1862ccfb32cSotto.Nm
1872ccfb32cSottowrote non-matching lines without reordering the fields.
1882ccfb32cSottoThe current version writes the join field first, followed by the
1892ccfb32cSottoremaining fields.
1902ccfb32cSotto.Pp
1912ccfb32cSottoFor compatibility with historical versions of
192df930be7Sderaadt.Nm join ,
193df930be7Sderaadtthe following options are available:
194df930be7Sderaadt.Bl -tag -width Fl
195df930be7Sderaadt.It Fl a
196df930be7SderaadtIn addition to the default output, produce a line for each unpairable line
197e8b5f1bcSjmcin both
198e8b5f1bcSjmc.Ar file1
199e8b5f1bcSjmcand
200e8b5f1bcSjmc.Ar file2 .
201df930be7Sderaadt.It Fl j Ar field
202df930be7SderaadtJoin on the
203df930be7Sderaadt.Ar field Ns 'th
204e8b5f1bcSjmcfield of both
205e8b5f1bcSjmc.Ar file1
206e8b5f1bcSjmcand
207e8b5f1bcSjmc.Ar file2 .
208e8b5f1bcSjmc.It Fl j1 Ar field
209e8b5f1bcSjmcJoin on the
210e8b5f1bcSjmc.Ar field Ns 'th
211e8b5f1bcSjmcfield of
212e8b5f1bcSjmc.Ar file1 .
213e8b5f1bcSjmc.It Fl j2 Ar field
214e8b5f1bcSjmcJoin on the
215e8b5f1bcSjmc.Ar field Ns 'th
216e8b5f1bcSjmcfield of
217e8b5f1bcSjmc.Ar file2 .
218df930be7Sderaadt.It Fl o Ar list ...
219df930be7SderaadtHistorical implementations of
220581190f2Saaron.Nm
221df930be7Sderaadtpermitted multiple arguments to the
222df930be7Sderaadt.Fl o
223df930be7Sderaadtoption.
224581190f2SaaronThese arguments were of the form
225581190f2Saaron.Dq file_number.field_number
226581190f2Saaronas described for the current
227df930be7Sderaadt.Fl o
228df930be7Sderaadtoption.
229581190f2SaaronThis has obvious difficulties in the presence of files named
230581190f2Saaron.Dq 1.2 .
231df930be7Sderaadt.El
232df930be7Sderaadt.Pp
2332ccfb32cSottoThese options are available only so historical shell scripts don't require
234df930be7Sderaadtmodification and should not be used.
2352ccfb32cSotto.Sh HISTORY
2362ccfb32cSottoA
2378cf461a5Saaron.Nm
2382ccfb32cSottoutility appeared in
2392ccfb32cSotto.At v7 .
240