Skip to content

Join command in Linux (join files)

The join command in Linux (join) joins the lines of both files that have a common index. The join command can be used as a simple database.

The commonly used options are:

  • -j1 number: Choose the number field as the index for file1.
  • -j2 number: Choose the number field as the index for file2.
  • -j number: Choose the number field as the index for both files.

Example:

Assume that file1 contains the following content:

1 GZH-1234 2 HYD-2389 3 GIS-2348

And file 2 has the following content:

1 Fiat Uno Mille Smart 2 Audi A3 3 Monza

After the command:

$ join —j 1 file1 file2

The output will be as follows:

1 GZH-134 Fiat Uni Mille Smart 2 HYD-2389 Audi A3 3 GIS-2348 Monza

TABLE - Symbols to differentiate header and footer

Symbol Description
::: Symbol used to start the text header
:: Symbol used to start the text body
: Symbol used to start the text footer
Note that the join command requires that both files contain an index, as in the example.

Learn much more about Linux in our online course. You can register here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it?

Share