Sorry if this is a duplicate question, but I could not find the answer that I am looking for here or in the documentation.
I have a file that looks like the following:
chr2_oligo1234 700 750 chr2_oligo1236 750 800 chr1_oligo1 50 100 chr1_oligo256 150 200 chr1_oligo6 3500 3550 chr4_oligo95 50 100 chr5_oligo1 50 100 chr4_oligo4 150 200
The desired output looks like:
chr1_oligo1 50 100 chr1_oligo256 150 200 chr1_oligo6 3500 3550 chr2_oligo1234 700 750 chr2_oligo1236 750 800 chr4_oligo95 50 100 chr4_oligo4 150 200 chr5_oligo1 50 100
The pattern at the start (e.g. chr#_oligo#) only matters in terms of the chr#, meaning that all chr1 should be first, then chr2, then chr3, etc., but I would like to sort those substrings numerically in groups as shown by the desired output above. So, I would like to know how to sort alphabetically in the case of the first column, and then keeping that order (chr1->chrN), sort each chunk of data numerically.
I apologize if my wording is not the best for this issue or if it is a duplicate. Trying
sort -k1,1 -nk2
does properly sort numerically, but does not keep the first sort intact (jumbles up the first column and places together all lines with columns 2 and 3 being like:
I am using Mac OS X.
EDIT: I want changed some of the examples in the first column to show more of what I'm looking for. gsort -V worked great if the name in the first column is in numerical order, but in my data set, it isn't always the case.
I would like to essentially sort each subgroup (in this case, chr1, chr2, etc) by column 2 iteratively. I realize this can be easily done by doing a grep for each and then sorting it on column 2, but I would like to know if sort or another unix command could accomplish this alone.