#!/usr/bin/python3 import sys import re volip={} regexp = "^(\S+) (\S+) (\S+) \[([^]]+)\] \"(\w+) (\S+).*\" (\d+) (\S+)" for line in sys.stdin: # on lit sur l’entrée standard line = line.rstrip () # on enleve le retour ligne res = re.match (regexp, line) if res: (host, rfc931, user, date, request, url, status, byte) = res.groups() host = res.group (1) byte = int(res.group (8)) #print ('host : ', host, ' byte : ', byte) if host not in volip: volip[host]=byte else: volip[host]=volip[host]+byte for addr in sorted(volip.keys()): print(addr, "", volip[addr])