| 用途 | 频次统计与排名 |
|---|---|
| 流水线 | cut/awk 提取 → sort → uniq -c → sort -rn → head |
| 变体 | sort -rn 数值降序 |
常用示例
常用示例
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -20
cut -d' ' -f9 access.log | sort | uniq -c | sort -rn
grep -o 'ERROR [a-z_]*' app.log | sort | uniq -c | sort -rn | headuniq -c 的计数在前、值在后;sort -rn 让最大计数排最前,head 截 TOP N。