join (Unix)

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

join is a command in 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.

The join command takes as input two text files and a number of 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 printing 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.

See also

External links

  • man page
  • join command
Retrieved from "https://en.wikipedia.org/w/index.php?title=Join_(Unix)&oldid=761126291"
This content was retrieved from Wikipedia : http://en.wikipedia.org/wiki/Join_(Unix)
This page is based on the copyrighted Wikipedia article "join (Unix)"; it is used under the Creative Commons Attribution-ShareAlike 3.0 Unported License (CC-BY-SA). You may redistribute it, verbatim or modified, providing that you comply with the terms of the CC-BY-SA