fbpx join Command in Linux: Merge Lines by Common Field | Certificação Linux

Linux join Command: Merge Files by Common Field

📅 01/01/2019 ⏱ 1 min ✍️ Uira Ribeiro
Linuxcommands
Linux join Command: Merge Files by Common Field
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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

The frequently used options are:

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

Example:

Suppose that file1 contains the following content:

1 GZH-12342 HYD-23893 GIS-2348

And file2 has the following content:

1 Fiat Uno Mille Smart2 Audi A33 Monza

After the command:

$ join –j 1 arquivo1 arquivo2

The output will be as follows:

1 GZH-134 Fiat Uni Mille Smart2 HYD-2389 Audi A33 GIS-2348 Monza

TABLE - Symbols to differentiate header and footer

SymbolDescription
\:\:\:Symbol used to start the text header
\:\:Symbol used to start the body of the text
\:Symbol used to start the text footer

Note that the join command requires both files to contain an index, as in the example.

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

Liked it? Share

 

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp