join(1)


join -- relational database operator

Synopsis

join [-a file_no | -v file_no\] [-e string\] [-o list\] [-t char\]
[-1 field] [-2 field] file1 file2

Description

join forms, on the standard output, a join of the two relations specified by the lines of file1 and file2. If either file1 or file2 is -, the standard input is used. file1 and file2 must be sorted in increasing code set collating sequence as specified by the LC_COLLATE environment variable on the fields on which they are to be joined, normally the first in each line (see sort(1)). join processes supplementary code set characters in files, and recognizes supplementary code set characters given to the -e and -t options according to the locale specified in the LC_CTYPE environment variable (see LANG on environ(5)).

The output contains one line for each pair of lines in file1 and file2 that have identical join fields. Each output line normally consists of the common field, then the rest of the line from file1, then the rest of the line from file2.

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.

Some of the options below use the argument file_no. This argument should be a 1 or a 2 referring to either file1 or file2, respectively.

Options


-a file_no
In addition to the normal output, produce a line for each unpairable line in file file_no, where file_no is 1 or 2. If both -a 1 and -a 2 are specified, all unpairable lines shall be output.

-e string
Replace empty output fields with string string. string may contain supplementary code set characters.

-j field
Equivalent to: -1 field -2 field

-j1 field
Equivalent to: -1 field

-j2 field
Equivalent to: -2 field

-o list
Each output line includes the fields specified in list, each element of which has the form file_no.field; 0 (zero) in list specifies the join field. The join field is not printed unless specifically requested. The elements of the list are either comma or blank separated, but should form one command-line argument. Fields selected by list that do not appear in the input are treated as empty output strings (see -e).

-t char
Use character c as a separator (tab character). Every appearance of c in a line is significant. The character c is used as the field separator for both input and output. c may be a supplementary code set character.

-v file_no
Instead of the default output, write a line only for each unpairable line in file_no. If both -v 1 and -v 2 are specified, all unpairable lines shall be output.

-1 field
Join on the fieldth field of file1. Fields are positive decimal integers starting with 1.

-2 field
Join on the fieldth field of file2. Fields are positive decimal integers starting with 1.

Examples

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 code set collating sequence on the group ID fields.

join -1 4 -2 3 -o 1.1 2.1 1.6 -t : /etc/passwd /etc/group

Files


/usr/lib/locale/locale/LC_MESSAGES/uxdfm
language-specific message file (see LANG on environ(5)).

References

awk(1), comm(1), sort(1), uniq(1)

Notices

With default field separation, the collating sequence is that of sort -b; with -t, the sequence is that of a plain sort.

The conventions of the join, sort, comm, uniq, and awk commands are wildly incongruous.

The -j, -j1, and -j2 options have been made obsolete by POSIX. It is recommended that application authors avoid using these options.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004