Python counter to text file
Question: So im trying to analyse a log file and extract information from it. One of the
things im trying to do is extract a list of IP addresses that have more than
30 failed attempts. In this a failed attempt is one that starts with the line
failed password for.

I have an idea for this that i wanted to try as i wasn't sure whether it will
work.

If i use python to create a counter that looks for the keyword failed that i
total and print out

This is what i have so far

    
    
    failed_line=0
    with open('blacklisttips.txt') as f2:
        lines= f1.readlines()
        for i, line in enumerate (lines):
            if line.startswith(failed_line):
                f2.write(line)
                f2.write(lines[i+1])
    


Answer: So let's say your file looks like this:

    
    
    failed password for 192.168.1.1
    failed password for 192.168.1.2
    ...
    more similar lines
    
    
    import collections
    
    prefix = failed password for
    with open('path/to/file') as infile:
        counts = collections.Counter(line.rsplit(" ",1)[1] for line in infile)
    

