Kalin Borisov
Kalin Borisov

Reputation: 1120

Sort specific column and order everything by high number to the low

Won't to order column status by high number to lower.

{"ipaddr":"10.1.2.72","hostname":"qr01034","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":74,"diskusage":"/home/u0261072"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":74,"diskusage":"/home/u0261072"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":79,"diskusage":"/"},
{"ipaddr":"10.1.2.74","hostname":"qr01036","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.74","hostname":"qr01036","status":8,"diskusage":"/"},
{"ipaddr":"10.1.2.75","hostname":"qr01037","status":1,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.75","hostname":"qr01037","status":34,"diskusage":"/"},
{"ipaddr":"10.1.2.75","hostname":"qr01037","status":74,"diskusage":"/mnt/"},
{"ipaddr":"10.1.2.76","hostname":"qr01038","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.76","hostname":"qr01038","status":34,"diskusage":"/"},
{"ipaddr":"10.1.2.77","hostname":"qr01039","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.77","hostname":"qr01039","status":63,"diskusage":"/"},
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":63,"diskusage":"/staging/"},
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":74,"diskusage":"/mnt/"}
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":81,"diskusage":"/"},

I try with

sort -t: -k3,3r

but without success ....

Expected view:

{"ipaddr":"10.1.2.78","hostname":"qr01040","status":81,"diskusage":"/"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":79,"diskusage":"/"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":74,"diskusage":"/home/u0261072"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":74,"diskusage":"/home/u0261072"},
{"ipaddr":"10.1.2.75","hostname":"qr01037","status":74,"diskusage":"/mnt/"},
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":74,"diskusage":"/mnt/"}
{"ipaddr":"10.1.2.77","hostname":"qr01039","status":63,"diskusage":"/"},
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":63,"diskusage":"/staging/"},
{"ipaddr":"10.1.2.76","hostname":"qr01038","status":34,"diskusage":"/"},
{"ipaddr":"10.1.2.75","hostname":"qr01037","status":34,"diskusage":"/"},
{"ipaddr":"10.1.2.74","hostname":"qr01036","status":8,"diskusage":"/"},
{"ipaddr":"10.1.2.75","hostname":"qr01037","status":1,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.77","hostname":"qr01039","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.76","hostname":"qr01038","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.74","hostname":"qr01036","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.72","hostname":"qr01034","status":0,"diskusage":"/dev/shm"},
{"ipaddr":"10.1.2.78","hostname":"qr01040","status":0,"diskusage":"/dev/shm"},

Upvotes: 0

Views: 89

Answers (1)

Barmar
Barmar

Reputation: 781592

Try:

sort -t: -k4,4rn

The n modifier means to sort numerically instead of lexicographically. And the status number is field 4, not 3. Here are the fields:

{"ipaddr":"10.1.2.74","hostname":"qr01036","status":0,"diskusage":"/dev/shm"},
<---1---> <---------2----------> <-------3--------> <-----4-----> <----5----->

Upvotes: 5

Related Questions