join joins two databases.
It assumes that both file1 and file2
contain textual databases in which each input line is a record and
that the input records are sorted in ascending order on a particular
join key field (by default the first field in each file).
If you specify
Conceptually, join computes the Cartesian product of records from both files. By default, spaces or tabs separate input fields and join discards any leading or trailing white space. (There can be no white-space delimited empty input fields.) It then generates output for those combined records in which the join key field (the first field by default) matches in each file. The default output for join is the common join key field followed first by all the other fields in file1, then all the other fields in file2. The other fields from each file appear in the same order they appeared in the original file. The default output field separator is a space character.
produces an output line for lines that do not match in addition to one for a pair of records that do match. If you specify n as one of 1 or 2, join produces unpaired records from only that file. If you specify both
-a1 and -a2, it produces unpaired records from both files. -estring
replaces empty fields (selected by
-o) with string on output. -i
ignores case when comparing fields.
uses field number m as the join key field. By default, the join key field is the first field in each input line. As with the
-aoption, if n is present, this option specifies the key field just for that file; otherwise, it specifies it for both files. -olist ...
specifies the fields to be output. You can specify each element in list as either n.m where n is a file number (1 or 2) and m is a field number, or as 0 (zero), which represents the join field. You can specify any number of output fields by separating them with blanks or commas. The POSIX-compatible form (listed first in SYNOPSIS) requires that you specify multiple output fields as a single argument; therefore shell quoting may be necessary. join outputs the fields in the order you list them.
sets the field separator to the character c. Each instance of c introduces a new field, making empty fields possible.
suppresses matching lines. If you specify n as one of 1 or 2, join produces unpaired records from only that file. If you specify both
-v1 and -v2, it produces unpaired records from both files. This does not suppress any lines produced using the -aoption. -1n
uses the nth field of file1 as the join key field.
uses the nth field of file2 as the join key field.
The following script produces a report about files in the current directory containing file name, file mode, and a guess at what the file contains:
file * | tr -s ':' ';' >temp1 ls -l | tr -s ' ' ';' >temp2 join -t ';' -2 9 -o 1.1,2.1,1.2 -- temp1 temp2 rm temp
This example uses the POSIX implementation of the join command. Using the obsolete form of the command, the third line of the script might look like:
join -t ';' -j2 9 -o 1.1 2.1 1.2 temp1 temp2
Possible exit status values are:
Failure due to any of the following:
Failure due to an invalid command line argument.
Most diagnostics deal with argument syntax and are self-explanatory. For example:
- Badly constructed output list at "list"
indicates that the list for a
-ooption did not have the proper syntax.
Windows Server 2012. Windows 8.1. Windows Server 2012 R2. Windows 10. Windows Server 2016. Windows Server 2019. POSIX.2. x/OPEN Portability Guide 4.0. All UNIX systems.
POSIX considers the
The join command supplied with PTC MKS Toolkit should not be confused with the Windows join command.
PTC MKS Toolkit for Power Users
PTC MKS Toolkit for System Administrators
PTC MKS Toolkit for Developers
PTC MKS Toolkit for Interoperability
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
PTC MKS Toolkit 10.3 Documentation Build 39.