-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux join Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to join on Linux, covering Arch Linux, CachyOS, and other distributions including joining files, database-like operations, and file merging.
join joins lines from two files on common field.
Uses:
- Join files: Merge files on common field
- Database operations: SQL-like joins
- Data merging: Combine data sets
- File operations: Merge related data
Why it matters:
- Data processing: Merge related data
- Database-like: SQL join operations
- File merging: Combine files
Basic usage:
# Join on first field (default)
join file1.txt file2.txt
# Files must be sorted on join fieldSpecify field:
# Join on field 2
join -1 2 -2 2 file1.txt file2.txt
# -1 2 = file1 field 2
# -2 2 = file2 field 2Default output:
# Output: join_field file1_other_fields file2_other_fields
join file1.txt file2.txtFormat output:
# Format output
join -o 1.1,2.2 file1.txt file2.txt
# -o = output formatSelect fields:
# Select specific fields
join -o 1.1,1.2,2.3 file1.txt file2.txt
# file1 field1, file1 field2, file2 field3Handle missing:
# Include unmatched lines
join -a 1 file1.txt file2.txt
# -a = include unmatched from file1Sort first:
# Sort on join field
sort -k1 file1.txt > file1.sorted.txt
sort -k1 file2.txt > file2.sorted.txt
join file1.sorted.txt file2.sorted.txtThis guide covered join usage, file joining, and data merging for Arch Linux, CachyOS, and other distributions.
- sort Guide - Sorting files
- cut Guide - Field extraction
- comm Guide - File comparison
-
join Documentation:
man join
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.