I have the following test.txt data, and I want to to check the occurrence of each state and show it as summary output. I am able to count how many times which state occurred using following logic
for line in file:
if 'success' in line: count+=1
but I am unable to add a column and append it to the end like my output. Any help will be highly appreciated.
Sample Input
-------------------------
11/11/2015 9.9.9.9 30s success
11/11/2015 9.9.9.8 30s stuck
11/11/2015 9.9.9.9 30s Sync
11/11/2015 9.9.9.9 30s success
11/12/2015 9.9.9.9 30s success
11/12/2015 9.9.9.9 30s stuck
11/12/2015 9.9.9.9 30s stuck
11/12/2015 9.9.9.9 30s success
11/12/2015 9.9.9.8 30s success
11/12/2015 9.9.9.9 30s success
11/12/2015 9.9.9.9 30s stuck
11/12/2015 9.9.9.9 30s success
11/12/2015 9.9.9.9 30s Sync
11/12/2015 9.9.9.9 30s Sync
--------------------Output I want -------------------------
11/11/2015 9.9.9.9 success 2
11/11/2015 9.9.9.8 stuck 1
11/11/2015 9.9.9.9 Sync 1
11/12/2015 9.9.9.9 success 4
11/12/2015 9.9.9.9 stuck 3
11/12/2015 9.9.9.9 Sync 2
11/12/2015 9.9.9.8 success 1