1
本帖最后由 chekir 于 2013-9-25 16:48 编辑
访问词数最多的一个IP是59.58.137.166 ,共19次
[code[root@localhost sbin]# cat 1.txt |awk '{print $1}' |sort -n |uniq -c |sort -rn
19 59.58.137.166
17 64.31.32.131
16 210.72.154.243
12 36.249.165.107
12 27.184.41.29
10 120.42.87.69
10 112.111.188.62
9 58.246.163.139
8 124.127.244.1
7 37.200.90.32
7 27.153.216.118
7 220.200.34.162
7 120.68.200.219
7 110.90.241.171
6 58.246.163.68
5 36.250.184.249
5 221.4.142.65
5 116.224.137.48
5 115.238.178.233
5 111.161.31.178
5 109.87.146.37
4 61.154.210.225
4 60.28.126.9
4 60.190.160.120
4 58.246.163.39
4 58.246.163.172
4 36.40.150.14
4 27.153.219.80
4 222.215.0.216
4 219.142.50.168
4 198.245.50.215
4 180.153.74.15
4 180.153.72.13
4 125.41.57.105
4 121.25.189.186
4 114.80.109.30
4 111.196.183.252
3 61.180.112.50
3 61.135.189.101
3 222.84.117.118
3 219.142.50.162
3 218.30.103.128
3 183.39.192.108
3 183.238.123.118
3 183.129.165.126
3 183.12.69.70
3 180.153.73.25
3 175.160.177.243
3 123.151.43.78
3 121.232.253.150
3 117.26.78.174
3 113.240.185.227
2 84.202.94.130
2 69.30.238.18
2 61.161.152.18
2 61.135.190.221
2 60.221.225.46
2 60.209.221.242
2 60.177.79.79
2 58.246.163.12
2 58.20.215.14
2 46.161.41.24
2 27.17.61.85
2 220.163.101.244
2 219.238.244.11
2 219.238.178.4
2 219.159.240.124
2 219.142.50.166
2 219.140.82.13
2 218.95.214.12
2 218.85.138.135
2 218.30.103.83
2 218.30.103.122
2 211.148.117.139
2 208.177.76.8
2 199.193.117.38
2 199.182.236.216
2 188.165.223.74
2 183.60.215.4
2 183.60.215.23
2 180.153.160.116
2 178.69.125.110
2 175.8.115.59
2 157.55.32.58
2 124.205.44.34
2 123.150.199.233
2 122.81.105.130
2 120.40.149.187
2 119.188.91.99
2 117.30.113.224
2 117.26.202.90
2 116.10.195.227
2 115.238.188.210
2 115.238.178.238
2 115.238.178.236
2 113.116.61.207
2 112.240.16.61
2 112.111.176.144
2 111.206.51.17
2 106.120.100.194
2 101.226.167.244
1 [root@haotui-web
1 94.228.34.206
1 94.228.34.203
1 94.153.11.98
1 92.112.229.83
1 66.249.74.95
1 66.249.74.213
1 66.249.74.173
1 66.249.74.160
1 66.249.74.142
1 66.249.74.117
1 61.55.185.137
1 61.55.185.132
1 61.55.185.122
1 61.186.94.147
1 61.177.192.230
1 61.174.170.58
1 61.164.150.70
1 61.157.111.60
1 61.147.76.51
1 61.135.190.101
1 61.135.189.99
1 61.135.189.96
1 61.135.189.147
1 61.135.189.112
1 61.135.169.24
1 60.55.9.180
1 59.38.179.68
1 59.174.50.12
1 59.120.142.173
1 58.247.247.86
1 5.255.253.16
1 49.64.96.216
1 46.29.21.152
1 46.161.41.32
1 42.156.139.69
1 42.121.0.148
1 37.187.89.162
1 27.45.0.208
1 27.214.35.67
1 27.17.61.83
1 27.159.203.129
1 27.153.186.152
1 27.153.161.14
1 223.72.238.99
1 223.247.226.8
1 222.243.215.69
1 222.175.19.121
1 222.134.69.206
1 222.133.50.78
1 221.231.3.16
1 221.204.7.71
1 221.204.7.190
1 221.204.196.41
1 221.204.196.156
1 221.204.196.151
1 221.204.196.135
1 221.204.196.111
1 221.176.136.179
1 220.246.223.162
1 220.191.236.45
1 220.181.89.186
1 220.181.89.178
1 220.181.89.172
1 220.181.89.165
1 220.181.89.163
1 220.181.89.157
1 220.181.89.148
1 220.181.89.140
1 220.181.132.219
1 220.181.132.218
1 220.181.127.233
1 220.181.127.18
1 220.181.127.14
1 220.181.127.123
1 220.181.125.27
1 220.181.125.25
1 220.181.125.169
1 220.181.108.182
1 220.181.108.160
1 220.181.108.120
1 219.237.227.210
1 219.154.133.226
1 219.142.50.153
1 218.30.103.37
1 218.30.103.145
1 218.30.103.139
1 211.155.120.231
1 211.103.236.96
1 203.192.13.36
1 202.103.210.103
1 202.101.114.200
1 198.2.198.133
1 183.60.215.31
1 183.60.214.9
1 183.60.214.104
1 183.60.212.160
1 183.60.212.159
1 183.60.212.158
1 182.140.131.131
1 182.118.49.49
1 182.118.42.175
1 182.118.32.144
1 182.118.26.74
1 182.118.25.208
1 182.118.25.207
1 182.118.21.241
1 182.118.21.231
1 182.118.21.210
1 182.118.20.254
1 182.118.20.253
1 182.118.20.251
1 182.118.20.249
1 182.118.20.202
1 180.169.69.219
1 180.153.236.73
1 180.153.236.50
1 180.153.236.47
1 180.153.236.42
1 180.153.236.180
1 180.153.236.169
1 180.153.236.154
1 180.153.236.131
1 180.153.236.118
1 180.153.236.102
1 180.153.214.198
1 180.153.214.182
1 180.153.114.199
1 180.149.133.13
1 180.121.165.18
1 171.221.154.7
1 1.62.189.212
1 153.3.53.127
1 144.76.92.234
1 125.69.130.221
1 125.46.17.41
1 125.39.162.58
1 125.38.197.195
1 125.112.164.87
1 124.237.121.101
1 124.115.2.191
1 124.113.5.192
1 123.180.227.112
1 123.151.43.79
1 123.151.43.39
1 123.151.148.154
1 123.151.139.210
1 123.135.194.110
1 123.126.68.40
1 123.125.71.92
1 123.125.71.77
1 123.125.71.70
1 123.125.71.60
1 123.125.71.55
1 123.125.71.52
1 123.125.71.43
1 123.125.71.20
1 123.125.71.109
1 123.125.71.107
1 123.125.71.100
1 121.35.216.105
1 121.31.62.123
1 121.204.201.222
1 120.32.217.200
1 119.118.230.154
1 117.70.39.171
1 117.26.78.49
1 117.26.118.147
1 117.25.122.225
1 117.24.3.92
1 116.25.253.255
1 116.23.93.111
1 116.208.191.134
1 115.238.188.212
1 115.238.178.237
1 115.211.102.207
1 114.98.79.142
1 114.254.131.99
1 114.251.175.37
1 114.244.21.235
1 114.217.189.250
1 114.101.44.176
1 113.97.188.69
1 113.230.236.39
1 113.230.216.169
1 113.201.33.141
1 113.142.18.99
1 113.13.131.41
1 112.90.231.7
1 112.90.222.184
1 112.225.142.122
1 112.195.173.31
1 112.111.14.46
1 112.111.12.248
1 111.165.139.249
1 110.81.108.141
1 110.181.53.164
1 101.226.33.240
1 101.226.169.204
1 101.226.168.227
1 101.226.168.213
1 101.226.168.199
1 101.226.168.196
1 101.226.167.243
1 101.226.167.228
1 101.226.167.195
1 101.226.166.254
1 101.226.166.208
1 101.226.166.206
1 101.226.102.97
1
[/code]
- #! /bin/bash
- cat 1.txt |awk '{print $1}' |sort -n |uniq -c |sort -rn
[code[root@localhost sbin]# cat 1.txt |awk '{print $1}' |sort -n |uniq -c |sort -rn
19 59.58.137.166
17 64.31.32.131
16 210.72.154.243
12 36.249.165.107
12 27.184.41.29
10 120.42.87.69
10 112.111.188.62
9 58.246.163.139
8 124.127.244.1
7 37.200.90.32
7 27.153.216.118
7 220.200.34.162
7 120.68.200.219
7 110.90.241.171
6 58.246.163.68
5 36.250.184.249
5 221.4.142.65
5 116.224.137.48
5 115.238.178.233
5 111.161.31.178
5 109.87.146.37
4 61.154.210.225
4 60.28.126.9
4 60.190.160.120
4 58.246.163.39
4 58.246.163.172
4 36.40.150.14
4 27.153.219.80
4 222.215.0.216
4 219.142.50.168
4 198.245.50.215
4 180.153.74.15
4 180.153.72.13
4 125.41.57.105
4 121.25.189.186
4 114.80.109.30
4 111.196.183.252
3 61.180.112.50
3 61.135.189.101
3 222.84.117.118
3 219.142.50.162
3 218.30.103.128
3 183.39.192.108
3 183.238.123.118
3 183.129.165.126
3 183.12.69.70
3 180.153.73.25
3 175.160.177.243
3 123.151.43.78
3 121.232.253.150
3 117.26.78.174
3 113.240.185.227
2 84.202.94.130
2 69.30.238.18
2 61.161.152.18
2 61.135.190.221
2 60.221.225.46
2 60.209.221.242
2 60.177.79.79
2 58.246.163.12
2 58.20.215.14
2 46.161.41.24
2 27.17.61.85
2 220.163.101.244
2 219.238.244.11
2 219.238.178.4
2 219.159.240.124
2 219.142.50.166
2 219.140.82.13
2 218.95.214.12
2 218.85.138.135
2 218.30.103.83
2 218.30.103.122
2 211.148.117.139
2 208.177.76.8
2 199.193.117.38
2 199.182.236.216
2 188.165.223.74
2 183.60.215.4
2 183.60.215.23
2 180.153.160.116
2 178.69.125.110
2 175.8.115.59
2 157.55.32.58
2 124.205.44.34
2 123.150.199.233
2 122.81.105.130
2 120.40.149.187
2 119.188.91.99
2 117.30.113.224
2 117.26.202.90
2 116.10.195.227
2 115.238.188.210
2 115.238.178.238
2 115.238.178.236
2 113.116.61.207
2 112.240.16.61
2 112.111.176.144
2 111.206.51.17
2 106.120.100.194
2 101.226.167.244
1 [root@haotui-web
1 94.228.34.206
1 94.228.34.203
1 94.153.11.98
1 92.112.229.83
1 66.249.74.95
1 66.249.74.213
1 66.249.74.173
1 66.249.74.160
1 66.249.74.142
1 66.249.74.117
1 61.55.185.137
1 61.55.185.132
1 61.55.185.122
1 61.186.94.147
1 61.177.192.230
1 61.174.170.58
1 61.164.150.70
1 61.157.111.60
1 61.147.76.51
1 61.135.190.101
1 61.135.189.99
1 61.135.189.96
1 61.135.189.147
1 61.135.189.112
1 61.135.169.24
1 60.55.9.180
1 59.38.179.68
1 59.174.50.12
1 59.120.142.173
1 58.247.247.86
1 5.255.253.16
1 49.64.96.216
1 46.29.21.152
1 46.161.41.32
1 42.156.139.69
1 42.121.0.148
1 37.187.89.162
1 27.45.0.208
1 27.214.35.67
1 27.17.61.83
1 27.159.203.129
1 27.153.186.152
1 27.153.161.14
1 223.72.238.99
1 223.247.226.8
1 222.243.215.69
1 222.175.19.121
1 222.134.69.206
1 222.133.50.78
1 221.231.3.16
1 221.204.7.71
1 221.204.7.190
1 221.204.196.41
1 221.204.196.156
1 221.204.196.151
1 221.204.196.135
1 221.204.196.111
1 221.176.136.179
1 220.246.223.162
1 220.191.236.45
1 220.181.89.186
1 220.181.89.178
1 220.181.89.172
1 220.181.89.165
1 220.181.89.163
1 220.181.89.157
1 220.181.89.148
1 220.181.89.140
1 220.181.132.219
1 220.181.132.218
1 220.181.127.233
1 220.181.127.18
1 220.181.127.14
1 220.181.127.123
1 220.181.125.27
1 220.181.125.25
1 220.181.125.169
1 220.181.108.182
1 220.181.108.160
1 220.181.108.120
1 219.237.227.210
1 219.154.133.226
1 219.142.50.153
1 218.30.103.37
1 218.30.103.145
1 218.30.103.139
1 211.155.120.231
1 211.103.236.96
1 203.192.13.36
1 202.103.210.103
1 202.101.114.200
1 198.2.198.133
1 183.60.215.31
1 183.60.214.9
1 183.60.214.104
1 183.60.212.160
1 183.60.212.159
1 183.60.212.158
1 182.140.131.131
1 182.118.49.49
1 182.118.42.175
1 182.118.32.144
1 182.118.26.74
1 182.118.25.208
1 182.118.25.207
1 182.118.21.241
1 182.118.21.231
1 182.118.21.210
1 182.118.20.254
1 182.118.20.253
1 182.118.20.251
1 182.118.20.249
1 182.118.20.202
1 180.169.69.219
1 180.153.236.73
1 180.153.236.50
1 180.153.236.47
1 180.153.236.42
1 180.153.236.180
1 180.153.236.169
1 180.153.236.154
1 180.153.236.131
1 180.153.236.118
1 180.153.236.102
1 180.153.214.198
1 180.153.214.182
1 180.153.114.199
1 180.149.133.13
1 180.121.165.18
1 171.221.154.7
1 1.62.189.212
1 153.3.53.127
1 144.76.92.234
1 125.69.130.221
1 125.46.17.41
1 125.39.162.58
1 125.38.197.195
1 125.112.164.87
1 124.237.121.101
1 124.115.2.191
1 124.113.5.192
1 123.180.227.112
1 123.151.43.79
1 123.151.43.39
1 123.151.148.154
1 123.151.139.210
1 123.135.194.110
1 123.126.68.40
1 123.125.71.92
1 123.125.71.77
1 123.125.71.70
1 123.125.71.60
1 123.125.71.55
1 123.125.71.52
1 123.125.71.43
1 123.125.71.20
1 123.125.71.109
1 123.125.71.107
1 123.125.71.100
1 121.35.216.105
1 121.31.62.123
1 121.204.201.222
1 120.32.217.200
1 119.118.230.154
1 117.70.39.171
1 117.26.78.49
1 117.26.118.147
1 117.25.122.225
1 117.24.3.92
1 116.25.253.255
1 116.23.93.111
1 116.208.191.134
1 115.238.188.212
1 115.238.178.237
1 115.211.102.207
1 114.98.79.142
1 114.254.131.99
1 114.251.175.37
1 114.244.21.235
1 114.217.189.250
1 114.101.44.176
1 113.97.188.69
1 113.230.236.39
1 113.230.216.169
1 113.201.33.141
1 113.142.18.99
1 113.13.131.41
1 112.90.231.7
1 112.90.222.184
1 112.225.142.122
1 112.195.173.31
1 112.111.14.46
1 112.111.12.248
1 111.165.139.249
1 110.81.108.141
1 110.181.53.164
1 101.226.33.240
1 101.226.169.204
1 101.226.168.227
1 101.226.168.213
1 101.226.168.199
1 101.226.168.196
1 101.226.167.243
1 101.226.167.228
1 101.226.167.195
1 101.226.166.254
1 101.226.166.208
1 101.226.166.206
1 101.226.102.97
1
[/code]
0
一种实现方式:
- awk '{gsub(/\[.*/, "", $0);if($0 !~ /^$/){gsub(/[[:blank:]]-[[:blank:]]|[[:blank:]]/, "\n", $0);printf $0}}' 1.log | sort | uniq -c > result.log
0
awk '{sum[$1]++}END{for(i in sum)print i,sum)}' 1.log | sort -nrk 2
或者是 awk {print $1} 1.log |sort -n | uniq -c | sort -nr
或者是 awk {print $1} 1.log |sort -n | uniq -c | sort -nr
0
本帖最后由 游夜 于 2014-9-1 19:18 编辑
#/bin/bash
echo awk -F '[-| ]' '{print $1}' 1.log |grep -v ^[^0-9]|sort|uniq -c
看错内容了。以为IP后面是-连接。
#/bin/bash
echo awk -F '[-| ]' '{print $1}' 1.log |grep -v ^[^0-9]|sort|uniq -c
看错内容了。以为IP后面是-连接。
0
本帖最后由 程城 于 2014-9-10 00:55 编辑
#!/bin/bash
s= awk '{print $1}' 1.log | sort -n |uniq -c|sort -n
sum=`echo $s |awk '{print $1}'
echo "$sum"
或者:
awk '{print $1}' ipaddr.txt | sort -n |uniq -c |sort -n
sort -n 主要是纯数字排序
要用uniq之前需要排序。
#!/bin/bash
s= awk '{print $1}' 1.log | sort -n |uniq -c|sort -n
sum=`echo $s |awk '{print $1}'
echo "$sum"
或者:
awk '{print $1}' ipaddr.txt | sort -n |uniq -c |sort -n
sort -n 主要是纯数字排序
要用uniq之前需要排序。
0
#/bin/bash
#writen by alex.zhu on 2014.11.01 about "awk sort "
cat /test/1.log |awk '{print $1}'|uniq -c |sort -nr #以重复次数从多到少来排列
~
#writen by alex.zhu on 2014.11.01 about "awk sort "
cat /test/1.log |awk '{print $1}'|uniq -c |sort -nr #以重复次数从多到少来排列
~
0
本帖最后由 t236xuchunfang 于 2014-12-10 08:03 编辑
grep '^[0-9]' ip.txt |awk -F' ' '{print $1}' |sort -n|uniq -c|sort -n
grep '^[0-9]' ip.txt |awk -F' ' '{print $1}' |sort -n|uniq -c|sort -n
0
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: amingtest2.sh
# Revision: 1.0
# Date: 2014/12/16
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Notes: aminglinux shell exercises of 2013-09-25
# -------------------------------------------------------------------------------
file="/root/test/1.log"
if [ -e $file ];then
awk '{print $1}' $file |sort |uniq -c|sort -nr
else
echo "the test file is missing!"
exit 1
fi
# -------------------------------------------------------------------------------
# Filename: amingtest2.sh
# Revision: 1.0
# Date: 2014/12/16
# Author: FUQIANG LI
# Email: 317377106@qq.com
# Notes: aminglinux shell exercises of 2013-09-25
# -------------------------------------------------------------------------------
file="/root/test/1.log"
if [ -e $file ];then
awk '{print $1}' $file |sort |uniq -c|sort -nr
else
echo "the test file is missing!"
exit 1
fi
0
虽然实现效果了,但是写的不好
#! /bin/bash
# 通过访问日志统计出每个IP的访问量是多少?
file='/root/1.log';
echo `cat $file |awk -F ' ' '{print $1}' |sort -n |uniq -c` >> num.txt;
#! /bin/bash
# 通过访问日志统计出每个IP的访问量是多少?
file='/root/1.log';
echo `cat $file |awk -F ' ' '{print $1}' |sort -n |uniq -c` >> num.txt;
0
本帖最后由 寻@轨迹 于 2015-2-6 16:36 编辑
awk -F ' ' '{print $1}' access.log | grep -v '^$' | sort -n | uniq -c |sort -n
awk -F ' ' '{print $1}' access.log | grep -v '^$' | sort -n | uniq -c |sort -n
0
代码http://www.aminglinux.com/bbs/ ... xnone
- #!/bin/bash
- ##test by gxw
- ## 用数组实现
- log=/tmp/1.log
- ip=(`awk '{++ipa[$1]} END{for(i in ipa ) print i }' $log`)
- format=(`awk '{++ipa[$1]} END{for(i in ipa ) print i"的访问量:" ipa[i]}' $log`)
- length=${#ip[*]}
- len=$[$length-1]
- for i in `seq 0 $len`;do
- echo ${format[$i]}
- done
编辑回复