我希望此特定代码按大多数出现次数进行排序
cat /var/log/messages* |\
awk '{ print $2, $1, $5 }' | sort -k2,2M -k 1n |\
uniq -c | awk '{ print $2, $3, $1, $5, $4 }'
现在它是按日期排序的,我已经尝试过多次失败,并按大多数事件进行排序。
当前输出:
27 Apr 1 rhsmd:
27 Apr 1 rsyslogd:
28 Apr 1 rhsmd:
29 Apr 1 rhsmd:
30 Apr 1 rhsmd:
10 May 1 rhsmd:
11 May 1 rhsmd:
11 May 1 rsyslogd:
12 May 1 rhsmd:
13 May 1 rhsmd:
14 May 1 rhsmd:
15 May 1 rhsmd:
16 May 1 rhsmd:
17 May 1 rhsmd:
18 May 1 rhsmd:
18 May 1 rsyslogd:
19 May 1 rhsmd:
1 May 1 rhsmd:
20 May 1 rhsmd:
21 May 1 rhsmd:
22 May 1 automount[1091]:
22 May 1 console-kit-daemon[1435]:
22 May 1 cpuspeed:
22 May 1 irqbalance:
22 May 1 rhnsd[1258]:
22 May 1 rhnsd[1259]:
22 May 1 rhsmd:
22 May 1 rpcbind:
22 May 1 rpc.statd[861]:
22 May 1 sm-notify[862]:
22 May 239 kernel:
22 May 2 mcelog:
我希望22 May 239 kernel:
位于顶部,因为它发生了239次。
我试过sort -k3 -n
,但它就像这样
22 May 2 abrtd:
22 May 1 automount[1091]:
22 May 7 cloud:
22 May 1 console-kit-daemon[1435]:
22 May 1 cpuspeed:
22 May 7 init:
22 May 1 irqbalance:
22 May 239 kernel:
答案 0 :(得分:0)
只需更改为:
sort -k3 -rn -t' '
这将根据awk
输出的第3列进行排序。字段分隔符必须为' '
,订单必须相反。