Home·Terminal commands

join

Text processing

Usage

join -1 1 -2 1 [file1] [file2]

Joins two files on a shared field like a database join; both files must already be sorted on that field or lines silently drop out.

Common flags

FlagMeaning
-1Which field to use in the first file
-2Which field to use in the second file
-tThe field separator, as in -t,
-aAlso print unpaired lines from that file, an outer join
-vPrint only the unpaired lines from that file
-eFill missing fields with this string
-oChoose which fields the output holds

Examples

join -t, -1 1 -2 1 a.csv b.csv

Inner join on the first column.

join -a1 left.txt right.txt

Keeps the unmatched lines from the left file.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does join do?

Joins two files on a shared field like a database join; both files must already be sorted on that field or lines silently drop out.

Q. How do I type it?

join -1 1 -2 1 [file1] [file2] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man join. This command sits under Text processing.

Related commands

man page: man join