-
-
Save dketov/65b3cedc8033db4d30b89a716e23aece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Предположим, у нас есть access.log веб-сервера. | |
Как с помощью стандартных консольных средств найти десять IP-адресов, | |
от которых было больше всего запросов? | |
А как сделать это с помощью скрипта на Python? | |
""" | |
import sys | |
from collections import Counter | |
counter = Counter( | |
line.split(None, 1)[0] | |
for line in sys.stdin | |
) | |
freqdict = sorted( | |
counter.iteritems(), | |
key = lambda (k, v): v, | |
reverse = True | |
) | |
print "\n".join( | |
ip for ip, freq in | |
freqdict[:10] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Предположим, у нас есть access.log веб-сервера. | |
# Как с помощью стандартных консольных средств найти десять IP-адресов, | |
# от которых было больше всего запросов? | |
awk ' | |
{ counter[$1]++ } | |
END { | |
for(x in counter) | |
print counter[x], x; | |
} | |
' | | |
sort -k1 -n -r | | |
head -10 | | |
awk '{ print $2 }' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment