I'd like to combine the lines from two sorted files, not necessarily of the same length but with the same data fields and with the same header, starting after a maintained header based on the order of a particular column. For example, file 1 is:
header 1
header 2
header 3
cat 4 aa
dog 5 ab
ostrich 10 cd
fish 13 cc
and file 2 is:
header 1
header 2
header 3
lemur 3 dd
alligator 4 ca
lemming 16 ad
and I'd like to 1) keep the identical header but 2) sort the following lines based on column 2. The output I'd like is:
header 1
header 2
header 3
lemur 3 dd
cat 4 aa
alligator 4 ca
dog 5 ab
ostrich 10 cd
fish 13 cc
lemming 16 ad
I've looked but couldn't find a solution for exactly this situation using awk or join.