Linux join Command: Merge Files by Common Field
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
| Symbol | Description |
| \:\:\: | 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
That was just one piece. The course teaches the whole path — from your first command to exam day.