简体   繁体   中英

Multiple column sort in unix reverse order not working

I need to arrange the below, in the shown order. First based on 1st column, secondarily based on 3rd column.

148672074   ABC 23.77
148672073   ABC 13.77
148672074   ABC 53.77
148672071   ABC 23.77
148672074   ABC 93.77
148672074   ABC 193.77

I need it like,

148672071   ABC  23.77
148672073   ABC  13.77
148672074   ABC 193.77
148672074   ABC  93.77
148672074   ABC  53.77
148672074   ABC  23.77

I used the below command.

sort -t "\t" -k1,1n -k3,3rn a.txt >b.txt

However, I'm getting the output as

148672071   ABC  23.77
148672073   ABC  13.77
148672074   ABC 193.77
148672074   ABC  23.77
148672074   ABC  53.77
148672074   ABC  93.77

Somebody Please tell me where I'm going wrong? And kindly give me the right command.

PS: The file I'm using is a TSV format file, exported from an excel sheet.

\\t is recgnized as t , not as tab.

Instead of \\t , press Ctrl + V , then Tab to denote tab character.

$ sort -t " " -k1,1n -k3,3rn a.txt
148672071   ABC 23.77
148672073   ABC 13.77
148672074   ABC 193.77
148672074   ABC 93.77
148672074   ABC 53.77
148672074   ABC 23.77

UPDATE

As fedorqui commented, you can also use $'\\t' :

$ sort -t $'\t' -k1,1n -k3,3rn a.txt
148672071   ABC 23.77
148672073   ABC 13.77
148672074   ABC 193.77
148672074   ABC 93.77
148672074   ABC 53.77
148672074   ABC 23.77

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM