我具有以下格式的日志文件:
Dec 20 03:25:08 localhost logdelete: Misc info1
Dec 20 03:25:08 localhost run-parts(/etc/cron.daily)[12345]: Misc info2
Dec 20 03:26:21 localhost anacron[1122]: Misc info3
Dec 20 03:26:21 localhost anacron[1122]: Misc info4
Dec 20 03:30:01 localhost CROND[2233]: Misc info5
Dec 20 03:30:01 localhost CROND[2233]: Misc info6
Dec 20 05:03:03 localhost ntpd[3705]: Misc info7
Dec 20 05:20:01 localhost rsyslogd: Misc info8
Dec 20 05:22:04 localhost cs3[112233]: Misc info9
Dec 20 05:22:04 localhost cs3[112233]: Misc Info10
Dec 20 05:22:08 localhost cs3[112233]: Misc info11
Dec 20 05:22:08 localhost cs3[112233]: Misc info12
Dec 20 05:22:09 localhost cs3[112233]: Misc info14
Dec 20 05:22:37 localhost ACCT_ADD: Misc info15
我需要以以下方式解析Python中的日志文件,以便如果我将参数传递为Dec 20 05:2
,它将以以下方式为我提供输出:
minute,Message_total_count,rsyslogd,cs3,ACCT_AD
Dec 20 05:20,1,1,0,0
Dec 20 05:22,6,5,1,0
其中输出标头信息为==分钟,是用Dec 20 05:2
开头的任何内容,例如*Dec 20 05:20, Dec 20 05:21 ... Dec 20 05:29
,Message_total_count
是分钟内的日志消息总数,其后是进程名称从Dec 20 05:2
开始的时间内,它位于localhost(如rsyslogd,cs3,ACCT_AD)之后。
输出文件中的以下各行将包含分钟值,如Dec 20 05:20
,该分钟内的日志消息总数以及标头中列出的进程在日志文件中显示的次数。 ..希望问题清楚。
我无法理解要获得所需输出要遵循的逻辑。