join(1) User Commands join(1)NAMEjoin - relational database operator
SYNOPSIS
/usr/bin/join
/usr/src/join [-options file1 file2
ksh93
join [-options file1 file2
DESCRIPTIONjoin performs an equality join on the files file1 and file2 and writes
the resulting joined files to standard output. By default, a field is
delimited by one or more spaces and tabs with leading spaces and/or
tabs ignored. The -t option can be used to change the field delimiter.
The join field is a field in each file on which files are compared. By
default join writes one line in the output for each pair of lines in
files1 and files2 that have identical join fields. The default output
line consists of the join field, then the remaining fields from file1,
then the remaining fields from file2, but this can be changed with the
-o option. The -a option can be used to add unmatched lines to the out‐
put. The -v option can be used to output only unmatched lines.
The files file1 and file2 must be ordered in the collating sequence of
sort -b on the fields on which they are to be joined otherwise the
results are unspecified.
If either file1 or file2 is -, join uses standard input starting at the
current location.
This command conforms to IEEE Std 1003.1-2008.
OPTIONS
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
--unpairable=fileno
Write a line for each unpairable line in file fileno, where fileno
is either 1 or 2, in addition to the normal output. If -a options
appear for both 1 and 2, then all unpairable lines will be output.
-B
--mmap
Enable memory mapped reads instead of buffered. On by default. -B
means --nommap.
-e
--empty=string
Replace empty output fields in the list selected with -o with
string.
-i
--ignorecase
Ignore case in field comparisons.
-j
--join=field
Equivalent to -1 field -2 field.
-o
--output=list
Construct the output line to comprise the fields specified in a
blank or comma separated list list. Each element in list consists
of a file number (either 1 or 2), a period, and a field number or 0
representing the join field. As an obsolete feature multiple occur‐
rences of -o can be specified.
-t
--separator|tabs=delim=delim
Use delim as the field separator for both input and output.
-v
--suppress=fileno
Write a line for each unpairable line in file fileno, where fileno
is either 1 or 2, instead of the normal output. If -v options
appear for both 1 and 2, then all unpairable lines will be output.
-1
--j2=field
Join on field field of file1. Fields start at 1.
-2
--j1=field
Join on field field of file2. Fields start at 1.
--help
Print basic help information.
--man
--html
--nroff
Print built-in manual page in either plain text, HTML or nroff for‐
mat.
--version
Print version information.
The following option forms are also recognized: -j field is equivalent
to 1 field 2 field, -j1 field is equivalent to -1 field, and -j2 field
is equivalent to -2 field.
OPERANDS
The following operands are supported:
file1 A path name of a file to be joined. If either of the file1 or
file2 operands is −, the standard input is used in its place.
file2 A path name of a file to be joined. If either of the file1 or
file2 operands is −, the standard input is used in its place.
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)).
USAGE
See largefile(5) for the description of the behavior of join when
encountering files greater than or equal to 2 Gbyte (2^31 bytes).
EXAMPLES
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
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables
that affect the execution of join: LANG, LC_ALL, LC_CTYPE, LC_MESSAGES,
LC_COLLATE, and NLSPATH.
EXIT STATUS
The following exit values are returned:
0 All input files were output successfully.
>0 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
┌─────────────────────────────┬─────────────────────────────┐
│ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
├─────────────────────────────┼─────────────────────────────┤
│Availability │SUNWcs │
├─────────────────────────────┼─────────────────────────────┤
│CSI │Enabled │
├─────────────────────────────┼─────────────────────────────┤
│Interface Stability │Committed │
├─────────────────────────────┼─────────────────────────────┤
│Standard │See standards(5). │
└─────────────────────────────┴─────────────────────────────┘
SEE ALSOawk(1), comm(1), sort(1), uniq(1), attributes(5), environ(5), large‐
file(5), standards(5)
IEEE Std 1003.1-2008.
http://www.opengroup.org
NOTES
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.
SunOS 5.11 29 Nov 2009 join(1)