10:01:36 adcli
10:01:36 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 adcli
10:01:37 runma
10:01:37 runma
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 roots
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 adcli
10:01:37 adcli
10:01:37 sshd[
10:01:37 sshd[
这是我的方法:(我知道这不是一个完整的,但)
import re
i="sshd"
j="apached"
k="wexd"
count_a=0;
count_b=0;
count_c=0;
file=open("hex01.txt","r")
for line in file:
for datestamp in line[0:5]
if line.match("datestamp"):
print datestamp,m=line.count("sshd"),n=line.count("apached"),0=line.count ("wexd"),t=m+n+0
这是我试图用Python处理的示例输入数据。我知道使用bash获得输出相当容易,但是我正在学习Python,我觉得获得所需的输出相当困难。任何帮助都将被感激,我甚至不需要一个完美的代码,但算法和适当的python库就足够了。输出应该是
A进程计数,B进程计数,总计
例如:10:01:37 10,2,1,13
—表示10 sshd、2adcli和1来自上述日志文件
@Padriac,sum是所有进程的总和。在上一个示例中,如果您看到输出:10:01:37 10,2,1,13 13引用所有进程的总和10+2+1,那么该总和仍然缺失。祝你新年快乐!你知道吗
当我们看到一个新的时间戳时,可以使用dict.setdefault添加一个新的dict,并增加
sshd
等。。每次我们看到键时,键值为1:您还可以使用collections.Counterdict:
相关问题 更多 >
编程相关推荐