Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
User Commands (g - j) join(1)
If phonedir contains:
Binst 555-6235
Dickerson 555-1842
Eisner 555-1234
Green 555-2240
Hrarii 555-0256
Janatha 555-7358
Lewis 555-3237
Takata 555-5341
Wozni 555-1234
and names contains:
Eisner Dept. 389
Frost Dept. 217
Green Dept. 311
Takata Dept. 454
Wozni Dept. 520
then join -o 2.3,2.1,1.2 phonedir names displays:
389 Eisner 555-1234
311 Green 555-2240
454 Takata 555-5341
520 Wozni 555-1234
4. To perform a join operation on a field other than the first field, enter:
sort -b +1 -2 phonedir | join -1 2 - numbers
This command combines the lines in phonedir and names, comparing the second field of
phonedir to the first field of numbers.
First, this command sorts phonedir by the second field, because both files must be sorted
by the join field. The output of sort is then piped to join. The - (dash) by itself causes
the join command to use this sorted output as its file1. -1 2 defines the second field of the
sorted phonedir as the join field. This field is compared to the first field of numbers (its
join field is not specified with a -2 flag).
If phonedir contains:
Binst 555-6235
Dickerson 555-1842
Eisner 555-1234
Green 555-2240
Hrarii 555-0256
Janatha 555-7358
Lewis 555-3237
Takata 555-5341
Wozni 555-1234
527188-003 Hewlett-Packard Company 4−61