I want to merge some pre-sorted tab-delimited files:
- file
bygroup.0
:ancient-american mercury 1 164 ancient-american mh25 2 8717664 ancient-neolith tk11 262 40074321970 ancientdna jk21 6936 17069206689 ancientdna rm20 11267 372606702813 ancientgen ab34 1573 27800468142 ancientgen dg11 3516 45081427920 ancientgen fa8 7179 462396221983 ancientgen mp15 41 10248223517 ancientgen mp18 254 1049351143 ancientgen rm20 15100 1565340401 ancientgen tc9 1695 89861489631
- file
bygroup.2
:ancient-american mercury 1 160 ancient-american mh25 2 10362712888 ancient-neolith tk11 264 43842268110 ancientdna jk21 6919 16379509855 ancientdna rm20 11268 324906365415 ancientgen ab34 1577 33947364202 ancientgen dg11 3518 48092138390 ancientgen fa8 7174 472364587220 ancientgen mp15 39 32487920045 ancientgen mp18 254 1058177852 ancientgen rm20 15104 998615135 ancientgen tc9 1692 94858351562
You can see the 2 files have the same number of lines, and are in the same order based on columns 1 and 2, and the entries in those columns are the same.
Now I want to merge them so that all the lines with the same values in the first 2 columns are output sequentially.
I thought sort -m
would be all I'd need, but:
$ sort -m bygroup.*
ancient-american mercury 1 160
ancient-american mercury 1 164
ancient-american mh25 2 10362712888
ancient-american mh25 2 8717664
ancient-neolith tk11 262 40074321970
ancientdna jk21 6936 17069206689
ancientdna rm20 11267 372606702813
ancientgen ab34 1573 27800468142
ancientgen dg11 3516 45081427920
ancientgen fa8 7179 462396221983
ancientgen mp15 41 10248223517
ancientgen mp18 254 1049351143
ancientgen rm20 15100 1565340401
ancientgen tc9 1695 89861489631
ancient-neolith tk11 264 43842268110
ancientdna jk21 6919 16379509855
ancientdna rm20 11268 324906365415
ancientgen ab34 1577 33947364202
ancientgen dg11 3518 48092138390
ancientgen fa8 7174 472364587220
ancientgen mp15 39 32487920045
ancientgen mp18 254 1058177852
ancientgen rm20 15104 998615135
ancientgen tc9 1692 94858351562
(I get the same results with other options I added, eg. sort -k 1,2 -ifm
.)
It does what I expected for ancient-american, but not for the others. What's going on, and is there another fast and efficient way of doing this without resorting to a full sort (sort
works without the -m
here).
LC_COLLATE=C sort -m bygroup.*
or withLC_ALL=C
LC_COLLATE=C
worked. Make your comment an answer and I'll accept. (I can't justpaste
because the full set of data files don't always have all the same entries.)