join
Join lines of two sorted files on a common field, like a database join.
Synopsis
join [OPTION]... FILE1 FILE2
Examples
join users.txt orders.txt
join -t',' -1 2 -2 1 a.csv b.csv
join -a1 -e'NULL' left.txt right.txt
Common options
| Flag | Description |
|---|---|
| -1 | Join on field N of file 1 |
| -2 | Join on field N of file 2 |
| -t | Field separator character |
| -a | Print unpairable lines from specified file |
| -e | Replace 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