title: I need help to understand logic and solve code using python
body: <p>My background: I am a Network Engineer and started learning python to automate tasks. I don't have much experience in coding. I need help to understand and solve the coding issue, I've spent numerous hours to solve this coding problem using python but no luck. I have attached what I have done so far on this problem.</p>
  
  <pre class="lang-py prettyprint-override"><code># read file
  with open("C:\py\logfile.txt") as file:
      next(file)
      lines = file.read().splitlines()
      file.close()
  
  matchEst = []
  matchFail = []
  matchSyn = []
  counterEst = 0
  counterFail = 0
  counterSyn = 0
  
  for line in lines:
      line = line.strip()
  
      if line.find('Established') != -1:
          matchEst.append(line)
      elif line.find('Failed') != -1:
          matchFail.append(line)
      elif line.find('Syn') != -1:
          matchSyn.append(line)
  
  print(matchEst)
  print(matchFail)
  print(matchSyn)
  </code></pre>
  
  <p>OUTPUT:</p>
  
  <pre><code>['9/1/2013              1.1.1.1   0:10        Established', '9/1/2013              1.1.1.1   0:10        Established', '9/2/2013              1.1.1.1   0:10        Established', '9/2/2013              1.1.1.1   0:10        Established', '9/2/2013              1.1.1.2   0:10        Established', '9/2/2013              1.1.1.1   0:10        Established', '9/2/2013              1.1.1.1   0:10        Established']
  ['9/1/2013              1.1.1.2   0:10        Failed', '9/2/2013              1.1.1.1   0:10        Failed', '9/2/2013              1.1.1.1   0:10        Failed', '9/2/2013              1.1.1.1   0:10        Failed']
  ['9/1/2013              1.1.1.1   0:10        Syn', '9/2/2013              1.1.1.1   0:10        Syn', '9/2/2013              1.1.1.1   0:10        Syn']
  </code></pre>
  
  
  
  <p>Code Description: To parse file "logfile.txt" and print the counts of the status for every IP per day.</p>
  
  <pre><code>cat logfile.txt                     
  -----------------                   
  Date                  IP        Time        State    
  9/1/2013              1.1.1.1   0:10        Established
  9/1/2013              1.1.1.2   0:10        Failed
  9/1/2013              1.1.1.1   0:10        Syn
  9/1/2013              1.1.1.1   0:10        Established
  9/2/2013              1.1.1.1   0:10        Established
  9/2/2013              1.1.1.1   0:10        Failed
  9/2/2013              1.1.1.1   0:10        Failed
  9/2/2013              1.1.1.1   0:10        Established
  9/2/2013              1.1.1.2   0:10        Established
  9/2/2013              1.1.1.1   0:10        Established
  9/2/2013              1.1.1.1   0:10        Failed
  9/2/2013              1.1.1.1   0:10        Established
  9/2/2013              1.1.1.1   0:10        Syn
  9/2/2013              1.1.1.1   0:10        Syn
  </code></pre>
  
  <p>Output should look like:</p>
  
  <pre><code>9/1/2013              1.1.1.1   Established         2
  9/1/2013              1.1.1.2   Failed    1
  9/1/2013              1.1.1.1   Syn         1
  9/2/2013              1.1.1.1   Established         4
  9/2/2013              1.1.1.1   Failed    3
  9/2/2013              1.1.1.1   Syn         2
  9/2/2013              1.1.1.2   Established         1
  </code></pre>
  
  <p>Thank you!</p>