我有以下 test.txt 数据,我想检查每个状态的出现并将其显示为摘要输出。我可以使用以下逻辑计算哪个状态发生了多少次
for line in file:
if 'success' in line: count+=1
但我无法像我的输出一样添加一列并将其附加到末尾。任何帮助将不胜感激。
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