sorting - How to sort a file in unix both alphabetically and numerically on different fields? -


please don't think repeat of "sorting alphanumeric data in unix" question... looked @ other answers, , think case bit different!

i have data this:

a    192 d    112 d    188 c    091    281 b    919 

...and want sort first column 1 (alphabetically), , column 2 (numerically). tried using:

sort -n -k1,2 

...but gave me correctly sorted first field, wrong sorting second field (1000,1002,1003,10,1 ... instead of 1,10,1000,1002,1003).

can please suggest how sort these 2 columns way i'd like?

try using this:-

sort -k1,1 -k4,4n 
  • -n : makes program sort according numerical value
  • -k opts: sort data / fields using given column number. example, option -k 2 made program sort using second
    column of data. option -k 3,3n -k 4,4n sorts each column. first
    sort 3rd column , 4th column.

Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -