 <p>This is what you want to use:</p> <p><code>sort -t: -k 1.5,1.8n -k 2.1,2.7n inputfile 440c0401 mfcc.1.ark:9 440c0401 mfcc.1.ark:501177 440c0402 mfcc.2.ark:15681 440c0403 mfcc.3.ark:516849</code></p> <p>-t -separator of fields(should not be used elsewhere in the inputfile</p> <p><code>-k</code> is key for sorting(could be used > 1) <code>-k 1.5,1.8n</code> means: sort numerical(this tells the <code>n</code>) by the field 1 from 5th to 8th character. </p> <p>second <code>-k</code> tells sort the field 2 from the first to the 7th character numerically.</p>