| join | |
|---|---|
| Original author | Douglas McIlroy |
| Developer | AT&T Bell Laboratories |
| Initial release | January 1979; 47 years ago (1979-01) |
| Written in | C |
| Operating system | Unix,Unix-like,Plan 9 |
| Platform | Cross-platform |
| Type | Command |
| License | coreutils:GPLv3+ Plan 9:MIT License |
join is a command inUnix andUnix-likeoperating systems that merges the lines of two sortedtext files based on the presence of a commonfield. It is similar to the join operator used inrelational databases but operating on text files.
Thejoin command takes as input two text files and several options. If nocommand-line argument is given, this command looks for a pair of lines from the two files having the same first field (a sequence of characters that are different from space), and outputs a line composed of the first field followed by the rest of the two lines.
The program arguments specify whichcharacter to be used in place of space to separate the fields of the line, which field to use when looking for matching lines, and whether to output lines that do not match. The output can be stored to another file rather than printed usingredirection.
As an example, the two following files list the known fathers and the mothers of some people. Both files have been sorted on the join field — this is a requirement of the program.
george jimkumar gunaware
albert marthageorge sophie
The join of these two files (with no argument) would produce:
george jim sophie
Indeed, only "george" is common as a first word of both files.
To findPythagorean triples of the form(k, k+1, n).
$join<(foriin{1..9999};doprintf--'%010d\t%s\t%s\t%s\n'"$((2*i*(i+1)+1))""$i""$((i+1))";done)<(foriin{1..9999};doprintf--'%010d\t%s\n'"$((i**2))""$i";done)0000000025 3 4 50000000841 20 21 290000028561 119 120 1690000970225 696 697 9850032959081 4059 4060 5741
join is intended to be a relation database operator. It is part of theX/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and theSingle Unix Specification.[1][2]
The version ofjoin bundled inGNUcoreutils was written by Mike Haertel.[3] The command is available as a separate package forMicrosoft Windows as part of theUnxUtils collection ofnativeWin32ports of common GNU Unix-like utilities.[4]
printf – Shell and Utilities Reference,The Single UNIX Specification, Version 5 fromThe Open Groupprintf(1) – FreeBSD General CommandsManualjoin(1) – Linux General CommandsManual from ManKier.com