error_count = {}
user_count = {}
with open(argv[1], 'r') as f:
for line in f:
result1 = re.search(r" ticky: ERROR ([\w ]*) ",line)
if result1 is not None:
if result1[1] not in error_count:
error_count[result1[1]] = 0
else:
error_count[result1[1]] += 1
print (sorted(error_count.items(), key = operator.itemgetter(1), reverse=True))
I need to search a logfile and find error messages and then sort them in a dictionary from most occurred to least occurred. I'm able to reach here.
Next, I need to Insert column names as ("Error", "Count") at the zero index position of the sorted "error_count" dictionary. And lastly, I need to create a CSV file out of that dictionary. I'm stuck here. Someone, please help me how to solve this.