.\" .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for .\" permission to reproduce portions of its copyrighted documentation. .\" Original documentation from The Open Group can be obtained online at .\" http://www.opengroup.org/bookstore/. .\" .\" The Institute of Electrical and Electronics Engineers and The Open .\" Group, have given us permission to reprint portions of their .\" documentation. .\" .\" In the following statement, the phrase ``this text'' refers to portions .\" of the system documentation. .\" .\" Portions of this text are reprinted and reproduced in electronic form .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition, .\" Standard for Information Technology -- Portable Operating System .\" Interface (POSIX), The Open Group Base Specifications Issue 6, .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics .\" Engineers, Inc and The Open Group. In the event of any discrepancy .\" between these versions and the original IEEE and The Open Group .\" Standard, the original IEEE and The Open Group Standard is the referee .\" document. The original Standard can be obtained online at .\" http://www.opengroup.org/unix/online.html. .\" .\" This notice shall appear on any product containing this material. .\" .\" The contents of this file are subject to the terms of the .\" Common Development and Distribution License (the "License"). .\" You may not use this file except in compliance with the License. .\" .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE .\" or http://www.opensolaris.org/os/licensing. .\" See the License for the specific language governing permissions .\" and limitations under the License. .\" .\" When distributing Covered Code, include this CDDL HEADER in each .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE. .\" If applicable, add the following below this CDDL HEADER, with the .\" fields enclosed by brackets "[]" replaced with your own identifying .\" information: Portions Copyright [yyyy] [name of copyright owner] .\" .\" .\" Copyright 1989 AT&T .\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Portions Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved .\" .TH JOIN 1 "Feb 8, 2000" .SH NAME join \- relational database operator .SH SYNOPSIS .LP .nf \fBjoin\fR [\fB-a\fR \fIfilenumber\fR | \fB-v\fR \fIfilenumber\fR] [\fB-1\fR \fIfieldnumber\fR] [\fB-2\fR \fIfieldnumber\fR] [\fB-o\fR \fIlist\fR] [\fB-e\fR \fIstring\fR] [\fB-t\fR \fIchar\fR] \fIfile1\fR \fIfile2\fR .fi .LP .nf \fBjoin\fR [\fB-a\fR \fIfilenumber\fR] [\fB-j\fR \fIfieldnumber\fR] [\fB-j1\fR \fIfieldnumber\fR] [\fB-j2\fR \fIfieldnumber\fR] [\fB-o\fR \fIlist\fR] [\fB-e\fR \fIstring\fR] [\fB-t\fR \fIchar\fR] \fIfile1\fR \fIfile2\fR .fi .SH DESCRIPTION .sp .LP The \fBjoin\fR command forms, on the standard output, a join of the two relations specified by the lines of \fIfile1\fR and \fIfile2\fR. .sp .LP There is one line in the output for each pair of lines in \fIfile1\fR and \fIfile2\fR that have identical join fields. The output line normally consists of the common field, then the rest of the line from \fIfile1\fR, then the rest of the line from \fIfile2\fR. This format can be changed by using the \fB-o\fR option (see below). The \fB-a\fR option can be used to add unmatched lines to the output. The \fB-v\fR option can be used to output only unmatched lines. .sp .LP The default input field separators are blank, tab, or new-line. In this case, multiple separators count as one field separator, and leading separators are ignored. The default output field separator is a blank. .sp .LP If the input files are not in the appropriate collating sequence, the results are unspecified. .SH OPTIONS .sp .LP Some of the options below use the argument \fIfilenumber\fR. This argument should be a \fB1\fR or a \fB2\fR referring to either \fIfile1\fR or \fIfile2\fR, respectively. .sp .ne 2 .na \fB\fB-a\fR \fIfilenumber\fR \fR .ad .RS 20n In addition to the normal output, produce a line for each unpairable line in file \fIfilenumber\fR, where \fIfilenumber\fR is \fB1\fR or \fB2\fR. If both \fB-a\fR \fB1\fR and \fB-a\fR \fB2\fR are specified, all unpairable lines will be output. .RE .sp .ne 2 .na \fB\fB-e\fR \fIstring\fR \fR .ad .RS 20n Replace empty output fields in the list selected by option \fB-o\fR with the string \fIstring\fR. .RE .sp .ne 2 .na \fB\fB-j\fR \fIfieldnumber\fR \fR .ad .RS 20n Equivalent to \fB-1\fR\fIfieldnumber\fR \fB-\fR\fB2\fR\fIfieldnumber\fR. .RE .sp .ne 2 .na \fB\fB-j1\fR \fIfieldnumber\fR \fR .ad .RS 20n Equivalent to \fB-1\fR\fIfieldnumber\fR. .RE .sp .ne 2 .na \fB\fB-j2\fR \fIfieldnumber\fR \fR .ad .RS 20n Equivalent to \fB-2\fR\fIfieldnumber\fR. Fields are numbered starting with \fB1\fR. .RE .sp .ne 2 .na \fB\fB-o\fR \fIlist\fR \fR .ad .RS 20n Each output line includes the fields specified in \fIlist\fR. Fields selected by \fIlist\fR that do not appear in the input will be treated as empty output fields. (See the \fB-e\fR option.) Each element of which has the either the form \fIfilenumber\fR\fB\&.\fR\fIfieldnumber\fR\fB,\fR or \fB0\fR, which represents the \fBjoin\fR field. The common field is not printed unless specifically requested. .RE .sp .ne 2 .na \fB\fB-t\fR \fIchar\fR \fR .ad .RS 20n Use character \fIchar\fR as a separator. Every appearance of \fIchar\fR in a line is significant. The character \fIchar\fR is used as the field separator for both input and output. With this option specified, the collating term should be the same as \fBsort\fR without the \fB-b\fR option. .RE .sp .ne 2 .na \fB\fB-v\fR \fIfilenumber\fR \fR .ad .RS 20n Instead of the default output, produce a line only for each unpairable line in \fIfilenumber\fR, where \fIfilenumber\fR is \fB1\fR or \fB2\fR. If both \fB-v\fR \fB1\fR and \fB-v\fR \fB2\fR are specified, all unpairable lines will be output. .RE .sp .ne 2 .na \fB\fB-1\fR \fIfieldnumber\fR \fR .ad .RS 20n Join on the \fIfieldnumber\fRth field of file 1. Fields are decimal integers starting with \fB1\fR. .RE .sp .ne 2 .na \fB\fB-2\fR\fIfieldnumber\fR \fR .ad .RS 20n Join on the \fIfieldnumber\fRth field of file 2. Fields are decimal integers starting with \fB1\fR. .RE .SH OPERANDS .sp .LP The following operands are supported: .sp .ne 2 .na \fB\fIfile1\fR \fR .ad .RS 10n .RE .sp .ne 2 .na \fB\fIfile2\fR \fR .ad .RS 10n A path name of a file to be joined. If either of the \fIfile1\fR or \fIfile2\fR operands is \fB\(mi\fR, the standard input is used in its place. .RE .sp .LP \fIfile1\fR and \fIfile2\fR must be sorted in increasing collating sequence as determined by \fBLC_COLLATE\fR on the fields on which they are to be joined, normally the first in each line (see \fBsort\fR(1)). .SH USAGE .sp .LP See \fBlargefile\fR(5) for the description of the behavior of \fBjoin\fR when encountering files greater than or equal to 2 Gbyte (2^31 bytes). .SH EXAMPLES .LP \fBExample 1 \fRJoining the password file and group file .sp .LP The following command line will join the password file and the group file, matching on the numeric group ID, and outputting the login name, the group name and the login directory. It is assumed that the files have been sorted in \fBASCII\fR collating sequence on the group ID fields. .sp .in +2 .nf example% \fBjoin -j1 4-j2 3 -o 1.1 2.1 1.6 -t:/etc/passwd /etc/group\fR .fi .in -2 .sp .LP \fBExample 2 \fRUsing the -o option .sp .LP The \fB-o\fR \fB0\fR field essentially selects the union of the join fields. For example, given file \fBphone\fR: .sp .in +2 .nf !Name Phone Number Don +1 123-456-7890 Hal +1 234-567-8901 Yasushi +2 345-678-9012 .fi .in -2 .sp .sp .LP and file \fBfax\fR: .sp .in +2 .nf !Name Fax Number Don +1 123-456-7899 Keith +1 456-789-0122 Yasushi +2 345-678-9011 .fi .in -2 .sp .sp .LP where the large expanses of white space are meant to each represent a single tab character), the command: .sp .in +2 .nf example% \fBjoin -t"\fItab\fR" -a 1 -a 2 -e '(unknown)' -o 0,1.2,2.2 phone fax\fR .fi .in -2 .sp .sp .LP would produce .sp .in +2 .nf !Name Phone Number Fax Number Don +1 123-456-7890 +1 123-456-7899 Hal +1 234-567-8901 (unknown Keith (unknown) +1 456-789-012 Yasushi +2 345-678-9012 +2 345-678-9011 .fi .in -2 .sp .SH ENVIRONMENT VARIABLES .sp .LP See \fBenviron\fR(5) for descriptions of the following environment variables that affect the execution of \fBjoin\fR: \fBLANG\fR, \fBLC_ALL\fR, \fBLC_CTYPE\fR, \fBLC_MESSAGES\fR, \fBLC_COLLATE\fR, and \fBNLSPATH\fR. .SH EXIT STATUS .sp .LP The following exit values are returned: .sp .ne 2 .na \fB\fB0\fR \fR .ad .RS 7n All input files were output successfully. .RE .sp .ne 2 .na \fB\fB>0\fR \fR .ad .RS 7n An error occurred. .RE .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS box; c | c l | l . ATTRIBUTE TYPE ATTRIBUTE VALUE _ CSI Enabled _ Interface Stability Standard .TE .SH SEE ALSO .sp .LP \fBawk\fR(1), \fBcomm\fR(1), \fBsort\fR(1), \fBuniq\fR(1), \fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), \fBstandards\fR(5) .SH NOTES .sp .LP With default field separation, the collating sequence is that of \fBsort\fR \fB-\fR\fBb\fR; with \fB-t\fR, the sequence is that of a plain sort. .sp .LP The conventions of the \fBjoin\fR, \fBsort\fR, \fBcomm\fR, \fBuniq\fR, and \fBawk\fR commands are wildly incongruous.