join
Text processing
Usage
join -1 1 -2 1 [file1] [file2]Joins two files on a shared field like a database join; both files must already be sorted on that field or lines silently drop out.
Common flags
| Flag | Meaning |
|---|---|
| -1 | Which field to use in the first file |
| -2 | Which field to use in the second file |
| -t | The field separator, as in -t, |
| -a | Also print unpaired lines from that file, an outer join |
| -v | Print only the unpaired lines from that file |
| -e | Fill missing fields with this string |
| -o | Choose which fields the output holds |
Examples
join -t, -1 1 -2 1 a.csv b.csvInner join on the first column.
join -a1 left.txt right.txtKeeps the unmatched lines from the left file.
These were built to be piped together. Three joined commands are usually shorter than one that does everything.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does join do?
Joins two files on a shared field like a database join; both files must already be sorted on that field or lines silently drop out.
Q. How do I type it?
join -1 1 -2 1 [file1] [file2] — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
7 are listed here; the full set is in man join. This command sits under Text processing.
Related commands
man page: man join