JOIN

Join lines on a common field, writes to standard output a line for each pair of input lines that have identical join fields.

SYNTAX
join [Options]… File1 File2Description

Either FILE1 or FILE2 (but not both) can be &qt;-&qt;&qt;, meaning standard input. FILE1 and FILE2 should be already sorted in increasing textual order on the join fields, using the collating sequence specified by the &qt;LC_COLLATE&qt;&qt; locale.

Unless the &qt;-t&qt;&qt; option is given, the input should be sorted ignoring blanks at the start of the join field, as in &qt;sort -b&qt;&qt;. If the &qt;–ignore-case&qt;&qt; option is given, lines should be sorted without regard to the case of characters in the join field, as in &qt;sort
-f&qt;&qt;.

The defaults are:
The join field is the first field in each line;
Fields in the input are separated by one or more blanks, with leading blanks on the line ignored;
Fields in the output are separated by a space;
Each output line consists of the join field, the remaining fields from FILE1, then the remaining fields from FILE2.

OPTIONS

&qt;-a FILE-NUMBER&qt;&qt;
Print a line for each unpairable line in file FILE-NUMBER (either
&qt;1&qt;&qt; or &qt;2&qt;&qt;), in addition to the normal output.

&qt;-e STRING&qt;&qt;
Replace those output fields that are missing in the input with
STRING.

&qt;-i&qt;&qt;
&qt;–ignore-case&qt;&qt;
Ignore differences in case when comparing keys. With this option,
the lines of the input files must be ordered in the same way. Use
&qt;sort -f&qt;&qt; to produce this ordering.

&qt;-1 FIELD&qt;&qt;
&qt;-j1 FIELD&qt;&qt;
Join on field FIELD (a positive integer) of file 1.

&qt;-2 FIELD&qt;&qt;
&qt;-j2 FIELD&qt;&qt;
Join on field FIELD (a positive integer) of file 2.

&qt;-j FIELD&qt;&qt;
Equivalent to &qt;-1 FIELD -2 FIELD&qt;&qt;.

&qt;-o FIELD-LIST…&qt;&qt;
Construct each output line according to the format in FIELD-LIST.
Each element in FIELD-LIST is either the single character &qt;0&qt;&qt; or
has the form M.N where the file number, M, is &qt;1&qt;&qt; or &qt;2&qt;&qt; and N is
a positive field number.

A field specification of &qt;0&qt;&qt; denotes the join field. In most
cases, the functionality of the &qt;0&qt;&qt; field spec may be reproduced
using the explicit M.N that corresponds to the join field.
However, when printing unpairable lines (using either of the &qt;-a&qt;&qt;
or &qt;-v&qt;&qt; options), there is no way to specify the join field using
M.N in FIELD-LIST if there are unpairable lines in both files. To
give &qt;join&qt;&qt; that functionality, POSIX invented the &qt;0&qt;&qt; field
specification notation.

The elements in FIELD-LIST are separated by commas or blanks.
Multiple FIELD-LIST arguments can be given after a single &qt;-o&qt;&qt;
option; the values of all lists given with &qt;-o&qt;&qt; are concatenated
together. All output lines – including those printed because of
any -a or -v option – are subject to the specified FIELD-LIST.

&qt;-t CHAR&qt;&qt;
Use character CHAR as the input and output field separator.

&qt;-v FILE-NUMBER&qt;&qt;
Print a line for each unpairable line in file FILE-NUMBER (either
&qt;1&qt;&qt; or &qt;2&qt;&qt;), instead of the normal output.

Tags: