Join (Unix): Difference between revisions

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search
imported>Widefox
 
imported>Cimumetupp
 
Line 39: Line 39:


Indeed, only "george" is common as a first word of both files.
Indeed, only "george" is common as a first word of both files.
==Examples==
To find [[Pythagorean triple]]s of the form [[Pythagorean triple#Almost-isosceles Pythagorean triples|(k, k+1, n)]].
<syntaxhighlight lang="console">
$ join <(for i in {1..9999} ; do printf -- '%010d\t%s\t%s\t%s\n' "$((2*i*(i+1)+1))" "$i" "$((i+1))" ; done) <(for i in {1..9999} ; do printf -- '%010d\t%s\n' "$((i**2))" "$i" ; done)
0000000025 3 4  5
0000000841 20 21  29
0000028561 119 120  169
0000970225 696 697  985
0032959081 4059 4060  5741
</syntaxhighlight>


==History==
==History==
{{code|join}} is intended to be a relation database operator. It is part of the [[X/Open]] Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the [[Single Unix Specification]].<ref>{{man|cu|printf|SUS}}</ref><ref>{{man|1|printf|FreeBSD}}</ref>
{{code|join}} is intended to be a relation database operator. It is part of the [[X/Open]] Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the [[Single Unix Specification]].<ref>{{man|cu|printf|SUS}}</ref><ref>{{man|1|printf|FreeBSD}}</ref>


The version of <code>join</code> bundled in [[GNU]] [[coreutils]] was written by Mike Haertel.<ref>{{man|1|join|ManKier}}</ref> The command is available as a separate package for [[Microsoft Windows]] as part of the [[UnxUtils]] collection of [[Native (computing)|native]] [[Windows API|Win32]] [[porting|ports]] of common GNU Unix-like utilities.<ref>{{Cite web|url=http://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref>
The version of <code>join</code> bundled in [[GNU]] [[coreutils]] was written by Mike Haertel.<ref>{{man|1|join|ManKier}}</ref> The command is available as a separate package for [[Microsoft Windows]] as part of the [[UnxUtils]] collection of [[Native (computing)|native]] [[Windows API|Win32]] [[porting|ports]] of common GNU Unix-like utilities.<ref>{{Cite web|url=https://unxutils.sourceforge.net/|title=Native Win32 ports of some GNU utilities|website=unxutils.sourceforge.net}}</ref>


==See also==
==See also==

Latest revision as of 02:52, 3 November 2025

Template:Short description Template:Lowercase Script error: No such module "Infobox".Template:Template other Script error: No such module "Check for unknown parameters".Script error: No such module "Check for conflicting parameters". join is a command in Unix and Unix-like operating systems that merges the lines of two sorted text files based on the presence of a common field. It is similar to the join operator used in relational databases but operating on text files.

Overview

The join command takes as input two text files and several options. If no command-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 which character 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 using redirection.

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 jim
kumar gunaware
albert martha
george 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.

Examples

To find Pythagorean triples of the form (k, k+1, n).

$ join <(for i in {1..9999} ; do printf -- '%010d\t%s\t%s\t%s\n' "$((2*i*(i+1)+1))" "$i" "$((i+1))" ; done) <(for i in {1..9999} ; do printf -- '%010d\t%s\n' "$((i**2))" "$i" ; done)
0000000025 3 4  5
0000000841 20 21  29
0000028561 119 120  169
0000970225 696 697  985
0032959081 4059 4060  5741

History

join is intended to be a relation database operator. It is part of the X/Open Portability Guide since issue 2 of 1987. It was inherited into the first version of POSIX.1 and the Single Unix Specification.[1][2]

The version of join bundled in GNU coreutils was written by Mike Haertel.[3] The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[4]

See also

References

<templatestyles src="Reflist/styles.css" />

  1. printf – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group
  2. printf(1) – FreeBSD General Commands Manual
  3. [[[:Template:Man/ManKier]] join(Template:Man/ManKier)] – Template:Man/ManKier
  4. Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".

External links

Template:Sister project

Script error: No such module "Navbox". Template:Plan 9 commands Template:Core Utilities commands