JOIN(1) | User Commands | JOIN(1) |
join - relational database operator
join [-a filenumber | -v filenumber] [-1 fieldnumber]
[-2 fieldnumber] [-o list] [-e string] [-t char] file1 file2
join [-a filenumber] [-j fieldnumber] [-j1 fieldnumber]
[-j2 fieldnumber] [-o list] [-e string] [-t char] file1 file2
The join command forms, on the standard output, a join of the two relations specified by the lines of file1 and file2.
There is one line in the output for each pair of lines in file1 and file2 that have identical join fields. The output line normally consists of the common field, then the rest of the line from file1, then the rest of the line from file2. This format can be changed by using the -o option (see below). The -a option can be used to add unmatched lines to the output. The -v option can be used to output only unmatched lines.
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.
If the input files are not in the appropriate collating sequence, the results are unspecified.
Some of the options below use the argument filenumber. This argument should be a 1 or a 2 referring to either file1 or file2, respectively.
-a filenumber
-e string
-j fieldnumber
-j1 fieldnumber
-j2 fieldnumber
-o list
-t char
-v filenumber
-1 fieldnumber
-2fieldnumber
The following operands are supported:
file1
file2
file1 and file2 must be sorted in increasing collating sequence as determined by LC_COLLATE on the fields on which they are to be joined, normally the first in each line (see sort(1)).
See largefile(7) for the description of the behavior of join when encountering files greater than or equal to 2 Gbyte (2^31 bytes).
Example 1 Joining the password file and group file
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 ASCII collating sequence on the group ID fields.
example% join -j1 4-j2 3 -o 1.1 2.1 1.6 -t:/etc/passwd /etc/group
Example 2 Using the -o option
The -o 0 field essentially selects the union of the join fields. For example, given file phone:
!Name Phone Number Don +1 123-456-7890 Hal +1 234-567-8901 Yasushi +2 345-678-9012
and file fax:
!Name Fax Number Don +1 123-456-7899 Keith +1 456-789-0122 Yasushi +2 345-678-9011
where the large expanses of white space are meant to each represent a single tab character), the command:
example% join -t"tab" -a 1 -a 2 -e '(unknown)' -o 0,1.2,2.2 phone fax
would produce
!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
See environ(7) for descriptions of the following environment variables that affect the execution of join: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES, LC_COLLATE, and NLSPATH.
The following exit values are returned:
0
>0
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
CSI | Enabled |
Interface Stability | Standard |
awk(1), comm(1), sort(1), uniq(1), attributes(7), environ(7), largefile(7), standards(7)
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.
February 8, 2000 | OmniOS |