Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は Apache サーバー ログを持っており、どの IP アドレスが最も多くのトラフィックを生成したかを判断しようとしています。私はすでにそれをフォーマットすることができたので、IPとそのトラフィックをバイト単位で表示します:
xxx.xxx.xxx.xxx 915925 yyy.yyy.yyy.yyy 1193 zzz.zzz.zzz.zzz 2356
だから今、私は同じIPのバイトを結合して追加し、一番上の値を見つける方法を探しています.
何か案は?
ファイルに ip とトラフィックのバイトがある場合は、次を使用して作業を完了します。
cat file | perl -ane '$h{ $F[0] } += $F[1]; END { for ( sort keys %h ) { printf qq[%s %d\n], $_, $h{ $_ } } }' | sort -k2 -n -r
awk '{A[$1]+=$2;next}END{for(i in A){print i,A[i]}}' file | sort -k2 -n -r