不希望按照较高的数字来订购列状态。
{"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":"/"},
我尝试
sort -t: -k3,3r
但没有成功......
预期观点:
{"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"},
答案 0 :(得分:5)
尝试:
sort -t: -k4,4rn
n
修饰符表示按数字排序而不是按字典顺序排序。状态编号是字段4,而不是3.以下是字段:
{"ipaddr":"10.1.2.74","hostname":"qr01036","status":0,"diskusage":"/dev/shm"},
<---1---> <---------2----------> <-------3--------> <-----4-----> <----5----->