Linux记录-常用统计awk
#统计第一列ip的个数(uniq -c 打印重复行count计数)
cat ip.txt | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 10
#统计tcp连接状态个数
netstat -an | awk '/tcp/{print $6}' | sort | uniq -c
awk '{print $1}' test.txt | sort | uniq -c
#统计第一列ip的个数
awk '{sum[$1]+=1} END {for(k in sum) print k ":" sum[k]}' ip.txt
#统计前三个ip出现次数最多的(k按第一列排序)
sort ip.txt | uniq -c | sort -nr -t ' ' -k 1 | head -n 3
#统计access.log ip数量前10个
awk '{sum[$1]++}END{for(ip in sum) print ip, sum[ip]}' access.log | sort -rn -k 2|head -n 10
#ip数量大于2的(k按第二列排序)
awk '{sum[$1]++}END{for(ip in sum)if(sum[ip]>2) print ip, sum[ip]}' access.log | sort -rn -k 2
#统计状态码
awk '{sum[$6]++}END{for(status in sum)if(sum[status]>2300) print status, sum[status]}' access.log | sort -rn -k 2
#统计状态码为200的ip个数
awk '{if($6=="200")sum[$1,$6]++}END{for(ip_num in sum)print ip_num,sum[ip_num]}' access.log |sort -rn -k 2|head -5
最新文章
- iOS:GCD理解1(同步-异步、串行-并行)
- go http.Get请求 http.Post请求 http.PostForm请求 Client 超时设置
- prince2 证书有用吗
- IOS - socket 编程初体验
- C#学习7.31判断体重是否超标
- C语言中数组的几种输入
- Fragment中调用Activity的UI
- BZOJ2073: [POI2004]PRZ
- mysql procedure返回多数据集
- JavaScript高级程序设计51.pdf
- 《Linux内核修炼之道》 系列
- Overloads和Overrides在元属性继承上的特性
- 使用PPRevealSideViewController实现侧滑效果
- 设计模式--迪米特法则(Lod/LKP)
- POJ 2455 Secret Milking Machine(搜索-二分,网络流-最大流)
- MVC4数据注解和验证
- TensorFlow[1]:概念和简例
- bat脚本:Java一键编译(Javac java)
- 实现一个ordeeddict
- Ansible 脚本运行一次后,再次运行时出现报错情况,原因:ansible script 的格式不对,应改成Unix编码