Given a common log format, the following one-liner calculates the bandwidth used per IP from the Apache logs. and does it pretty darn quickly – under 2 seconds for a 200-MB file.


# awk ‘{array[$1]+=$10} END { for ( item in array ) print
array[item]/1048576 “MB”, item }’ access_log.processed | sort -n


Omit the -n argument to sort if you want the largest numbers to appear at the top of the output.

It generates output that looks like the following:


1.00981MB 66.249.71.109
1.13482MB 129.188.33.27
1.13523MB 95.108.150.241
1.1675MB 151.151.109.22
1.19112MB 12.213.224.36
1.27849MB 82.44.133.226
1.3791MB 66.249.71.39
1.45494MB 38.105.83.11
1.4975MB 207.200.116.6
1.68302MB 88.131.106.30


Leave a Reply