标签:lis pid dal coding eve res with open nbsp 用户
文本示例:
ts=2019-07-10T06:43:06523942Z pid=1875 tid=6320 version=e73c536 proto=http id=5a61a613e395f8832a372e4c1804ce10 http_url="/dev/ng.git/git-upload-pack" ip=10.10.5.9 xff_ip=10.10.5.9 user=wangdongdong repo=dev/ng repo_public=0 cmd=git-upload-pack fs_host=git-server-0b2c6f4a-a72d-11e8-9cba-000c294988e0 ac_ms=46.699 duration_ms=58.204 sr=1562740986465.729 ss=1562740986523.934 fs_sent=945 fs_recv=904 client_recv=1295 client_sent=1202 fsc_ms=0.274 log_level=INFO msg="http op done: (200)" http_status=200 imode=0 ts=2019-07-10T06:43:06603025Z pid=1875 tid=6323 version=e73c536 proto=http id=4930c2b5ce76d270a9d5b406433f3d55 http_url="/dev/ng.git/git-upload-pack" ip=10.10.5.9 xff_ip=10.10.5.9 user=wangdongdong repo=dev/ng repo_public=0 cmd=git-upload-pack fs_host=git-server-0b2c6f4a-a72d-11e8-9cba-000c294988e0 ac_ms=44.971 duration_ms=59.885 sr=1562740986543.132 ss=1562740986603.016 fs_sent=945 fs_recv=1184 client_recv=1420 client_sent=1470 fsc_ms=0.255 log_level=INFO msg="http op done: (200)" http_status=200 imode=0
import os import re file = open("E:\\desktop\\aaa.csv" , "w" , encoding=‘utf-8‘) with open("E:\desktop\GitHub_babeld_Log\\babeld.log" , "r" , encoding=‘utf-8‘) as da: for line in da: username = re.findall(r"(user=(\w){1,20}(-)?(\w){1,20} )", line) ip_list = re.findall(r‘(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)‘,line) if len(username) != 0: ip = ip_list[0] res = "".join(username[0]) + ‘,‘ + ".".join(ip) file.write(res+"\n") file.close()
标签:lis pid dal coding eve res with open nbsp 用户
原文地址:https://www.cnblogs.com/xingfuxiaokong/p/11393466.html