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