join file1 file2
Files are supposed to be sorted in the merge field. If it is not, you can do this:
join <(sort -V file1) <(sort -V file2)
Here's the AWK version ( sortcompensates for the non-deterministic AWK order):
awk '{a[$1]=a[$1] FS $2} END {for (i in a) print i a[i]}' file1 file2 | sort -V
This seems shorter and more readable than Perl's answer.
In gawk4, you can set the traversal order of the array:
awk 'BEGIN {PROCINFO["sorted_in"] = "@ind_num_asc"} {a[$1]=a[$1] FS $2} END {for (i in a) print i a[i]}' file1 file2
sort. @ind_num_asc - . . .
: -V (--version-sort) sort GNU sort coreutils 7.0 . @simlev, , , .