xref: /original-bsd/usr.bin/join/join.1 (revision 31e799e3)
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)join.1	6.4 (Berkeley) 12/13/90
7.\"
8.Dd
9.Dt JOIN 1
10.Os BSD 4.4
11.Sh NAME
12.Nm join
13.Nd relational database operator
14.Sh SYNOPSIS
15.Nm join
16.Op Fl a Ar file_number
17.Op Fl e Ar string
18.Op Fl j Ar file_number field
19.if n .br
20.Op Fl o Ar list
21.Op Fl t Ar char
22.Op Fl v Ar file_number
23.Ob
24.Fl \&1
25.Ar field
26.Oe
27.Ob
28.Fl \&2
29.Ar field
30.Oe
31.Ar file1
32.if n .br
33.Ar file2
34.Sh DESCRIPTION
35The join utility performs an ``equality join'' on the files
36.Ar file1
37and
38.Ar file2 .
39The joined files are written to the standard
40output.
41.Pp
42The ``join field'' is a field in each file on which the
43files are compared.
44There is one line in the output for
45each pair of lines in
46.Ar file1
47and
48.Ar file2
49which have identical
50join fields.
51The output line by default consists of the
52join field, then the remaining fields from
53.Ar file1 ,
54then the
55remaining fields from
56.Ar file2 .
57This format can be changed by
58using the
59.Fl o
60option (see below).
61.Pp
62The files file1 and file2 should be ordered in the collating
63sequence of
64.Li sort -b
65on the fields on which they are to be
66joined, by default the first in each line; Otherwise, all
67join field matches need not be reported.
68.Pp
69The default input field separators are <blank>s.
70In this
71case, multiple separators count as one field separator, and
72leading separators are ignored.
73The default output field
74separator is a <space>.
75.Pp
76The following options are available:
77.Tw Fl
78.Tc Fl a
79.Ws
80.Ar file_number
81.Cx
82In addition to the default output, produce a line
83for each unpairable line in file
84.Ar file_number ,
85where
86.Ar file_number
87is 1 or 2.
88.Tc Fl e
89.Ws
90.Ar string
91.Cx
92Replace empty output fields by the string
93.Ar string .
94.Tc Fl j
95.Ws
96.Ar file_number field
97.Cx
98Join on the
99.Sf Ar field 'th
100field of file
101.Ar file_number .
102If
103.Ar file_number
104is missing, (i.e., the
105first digit of the option argument is neither 1 nor
1062), use the
107.Sf Ar field 'th
108field in each file.
109Fields are
110decimal integers starting with 1.
111.Tc Fl o
112.Ws
113.Ar list
114.Cx
115Each output line comprises the fields specified in
116.Ar list ,
117each element of which has the form
118.Ql file_number.field ,
119where
120.Ar file_number
121is a file
122number and field is a decimal integer field number.
123The elements of list are either comma or <space> separated.
124The list is written only for lines with matching join fields,
125and is not output unless specifically requested.
126.Tc Fl t
127.Ws
128.Ar char
129.Cx
130Use character
131.Ar char
132as a separator, for both input
133and output.
134Every appearance of char in a line is
135significant.
136When this option is specified, the
137collating sequence should be the same as sort
138without the
139.Fl b
140option.
141.Tc Fl v
142.Ws
143.Ar file_number
144.Cx
145Instead of the default output, produce a line only
146for each unpairable line in
147.Ar file_number ,
148where
149.Ar file_number
150is 1 or 2.
151.Tc Fl 1
152.Ws
153.Ar field
154.Cx
155Join on the
156.Sf Ar field 'th
157field of file 1.
158Fields are
159decimal integers starting with 1.
160.Tc Fl 2
161.Ws
162.Ar field
163.Cx
164Join on the
165.Sf Ar field 'th
166field of file 2.
167Fields are
168decimal integers starting with 1.
169.Tp
170.Pp
171If both
172.Ql \-a 1
173and
174.Ql \-a 2
175are specified, both sets of information
176are output,
177.Ql \-a 2
178always first, regardless of the specified
179order.
180.Pp
181The following arguments are required:
182.Dw Fl
183.Di L
184.Dp Ar file1
185.Dp Ar file2
186A pathname of a file to be joined.
187If either of
188the
189.Ar file1
190or
191.Ar file2
192arguments is
193.Sq Fl
194the standard
195input is used in its place.
196.Dp
197.Pp
198The
199.Nm join
200utility exits 0 on success, and >0 if an error occurs.
201.Sh STANDARDS
202The
203.Nm join
204function is expected to be POSIX 1003.2 compatible.
205.Sh SEE ALSO
206.Xr awk 1
207.Xr comm 1 ,
208.Xr look 1
209.Xr sort 1 ,
210.Xr uniq 1 ,
211.Sh BUGS
212The conventions of
213.Nm join ,
214.Xr comm 1 ,
215.Xr sort 1 ,
216.Xr uniq 1 ,
217.Xr look 1
218and
219.Xr awk  1
220are wildly incongruous.
221