Text and processing

The join command

Combines two files by a common field, like a database query but with text.

Syntax

join archivo1 archivo2

Most useful options

-1 NJoin field of the first file
-2 NJoin field of the second
-a NAlso includes lines with no match

Copy-ready examples

$ printf '1 ana\n' > j1.txt && printf '1 madrid\n' > j2.txt && join j1.txt j2.txtJoin on the first field

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • The files must be sorted by the join field.

Related commands

FAQ

What if there is no match?

By default that line disappears; with -a it is kept.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course