Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I sort a text file with GNU sort starting with alphanumeric sort by one column, followed by numerical sort in the next column?

I tried sort -n -k1,2 file.txt, but it doesn't seem to work:

cluster-7402-walk-0270  100     136     SP3     0.959707
cluster-7402-walk-0270  113     137     SP1     0.959707
cluster-7402-walk-0270  117     136     SP2     0.959707
cluster-7402-walk-0270  117     136     SP4     0.959707
cluster-7402-walk-0270  118     140     SMAD4   0.984412
cluster-7402-walk-0270  121     144     ARNT    0.991913
cluster-7402-walk-0270  121     146     AHR     0.991913
cluster-7402-walk-0270  13      24      GTF2A1  0.965496
cluster-7402-walk-0270  13      24      GTF2A2  0.965496
share|improve this question
up vote 2 down vote accepted

For alphanumeric sorting you need to use version sort. The sorting type should be specified for each field, e.g. to sort alphanumerically on first column and numerically on next column use:

sort -k 1,1V -k 2,2n file.txt

See info sort and search for sort field specified for more on this.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .