File Viewing & Editing

join

Join lines of two sorted files on a common field, like a database join.

Synopsis

syntax
join [OPTION]... FILE1 FILE2

Examples

Join two files on first field
join users.txt orders.txt
Join CSVs on different columns
join -t',' -1 2 -2 1 a.csv b.csv
Left join with NULL for missing values
join -a1 -e'NULL' left.txt right.txt

Common options

FlagDescription
-1Join on field N of file 1
-2Join on field N of file 2
-tField separator character
-aPrint unpairable lines from specified file
-eReplace missing fields with string

About join

The `join` command join lines of two sorted files on a common field, like a database join. Text viewing and editing commands are fundamental tools in any Linux user's toolkit.

Linux treats almost everything as a file, so the ability to quickly inspect, filter, transform, and edit file contents from the command line is critical. These commands are regularly combined with pipes and redirects to build powerful data-processing pipelines.

The command accepts 5 commonly used flags shown above, though the full set of options is available in the man page (`man join`). The 3 examples on this page cover typical real-world usage patterns that you can copy and adapt for your own workflows.

Related commands

More File Viewing & Editing Commands

Other commands in the File Viewing & Editing category

Related tools