Using Join
By David Feimer
Posted August 4, 2026
The join(1) command can be used to join lines from two files. Jut like in a database.
For example, using the example from the 7th edition of “An Introduction to Database Systems”
File1
D1 Marketing 10M
D2 Development 12M
D3 Research 5M
File2
E1 Lopez D1 40K
E2 Cheng D1 42K
E3 Finzi D2 30K
E4 Saito D2 35K
The files must first be sorted. Otherwise, not all possible joinings might be made.
sort -k 1 date1 -o sorted1
sort -k 3 date2 -o sorted2
Then, you can run join on the sorted files:
join -1 1 -2 3 sorted1 sorted2
which gives you:
D1 Marketing 10M E1 Lopez 40K
D1 Marketing 10M E2 Cheng 42K
D2 Development 12M E3 Finzi 30K
D2 Development 12M E4 Saito 35K