join Joins lines from two files based on a common field

join [options] file1 file2

The join utility displays a single line for each pair of lines from file1 and file2 that have the same value in a common field called the join field. Both files must be sorted on the join field or join will not display the correct output.

Arguments

The join utility reads lines from file1 and file2 and, for each pair of lines, compares the specified join field from both lines. If you do not specify a join field, join takes the first field as the join field. If the join fields are the same, join copies the join field along with the rest of the lines from both files to standard output. You can specify a hyphen () in place of either filename (but not both) to cause ...

Get A Practical Guide to Linux Commands, Editors, and Shell Programming, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.