1. Technology

Your suggestion is on its way!

An email with a link to:

http://linux.about.com/library/cmd/blcmdl_join.htm

was emailed to:

Thanks for sharing About.com with others!

Linux / Unix Command: join
Command Library
NAME
join (join lines of two files on a common field)
SYNOPSIS
join [-a 1|2] [-v 1|2] [-e empty-string] [-o field-list...] [-t char] [-j[1|2] field] [-1 field] [-2 field] file1 file2
DESCRIPTION

join outputs a line for a pair of input lines, where one line is from file1 and the other from file2 and both have same value in the join fields. file1 and file2 should be already sorted in increasing order on the join fields. Unless the -t option is given, they should be sorted ignoring blanks at the start of the line, as sort does when given the -b option.

The following defaults are used: the join field is the first field in each line; the fields in the input are separated by one or more blanks (leading blanks on the line are ignored); fields in the output are separated by a space; each output line consists of the join field, followed by the remaining fields from file1, followed by the remaining fields from file2.

OPTIONS

-a file-number
Print a line for each unpairable line in file file-number (either 1 or 2), in addition to the normal output.

-e string
Replace empty output fields (those that are missing in the input) with string.

-1, -j1 field
Join on field field (a positive integer) of file 1.

-2, -j2 field
Join on field field (a positive integer) of file 2.

-j field
Equivalent to -1 field -2 field.

-o field-list...
Construct each output line according to the format in field-list. Each element in field-list consists
of a file number (either 1 or 2), a period, and a field number (a positive integer). The elements in
the list are separated by commas or blanks. Multiple field-list arguments can be given after a sin-
gle -o option; the values of all lists given with -o are concatenated together.

-t char
Use character char as the input and output field separator.

-v file-number
Print a line for each unpairable line in file file-number (either 1 or 2), instead of the normal output.

EXAMPLE

% join file1 file2 > file3

If the content of file1 is:

1 Barbara
2 Peter
3 Stan
4 Marie

and file2 is:

2 Dog
4 Car
7 Cat

the resulting file3 would be:

2 Peter Dog
4 Marie Car

Important: Use the man command (% man) to see how a command is used on your particular computer.

>> Linux Command Library Index

>> Also see Shell Command Library

You can opt-out at any time. Please refer to our privacy policy for contact information.

Discuss in my forum

©2014 About.com. All rights reserved.