如上图所示日志:
统计独立ip数:
cat localhost_access_log.2017-03-26.txt |grep -v grep|awk ‘{print $1}’ > uniquetest.txt
countip=sort uniquetest.txt|uniq -c
echo $countip
统计总流量数:
cat localhost_access_log.2017-03-26.txt |grep -v grep|awk ‘{print $9}’ >liul.txt
cat liul.txt|awk ‘{sum+=$1} END {print “sum= “,sum}’
统计平均流量数:
cat localhost_access_log.2017-03-26.txt |grep -v grep|awk ‘{print $9}’ > avg.txt
cat avg.txt|awk ‘{sum+=$1} END {print “avg= “,sum/NR}’
统计最大流量数:
cat localhost_access_log.2017-03-26.txt |grep -v grep|awk ‘{print $9}’ >liul.txt
cat liul.txt|awk ‘BEGIN {max = 0} {if ( $1
> max ) max=$1 fi } END {print “max =”,max}’
统计最小流量数:
cat localhost_access_log.2017-03-26.txt |grep -v grep|awk ‘{print $9}’ >liul.txt
cat liul.txt|awk ‘BEGIN {min = 9999999} { if ( $1 <min) min=$1 fi
} END {print “min= “,min}’
统计访问前十的资源:
cat localhost_access_log.2017-03-26.txt |awk -F' ' '{ if (index ($1,"192.168.1.111")!=0) print $7; else print $1 } '|sort|uniq -c|sort -n |tail -n 10
cat localhost_access_log.2017-03-26.txt |awk -F' ' '{ if (index ($1,"192.168.1.111")!=0 || index ($1,"192.168.1.107")!=0 ) print $7; else print $1 } '|sort|uniq -c|sort -n |tail -n 10