I want to parse a text file using python. I am using split command, to split the line at :,=. I am able to parse it successfully but I want the output as below.
Input:
customer1:124
clientID:1
Error=1
customer2:125
clientID:1
Error=2
customer3:126
clientID:1
Error=3
Desired output:
Customer | Error
customer1 1
customer2 2
customer3 3
Here is my code:
import re
with open('logfile','r') as log_data:
for line in log_data:
if line.startswith("customer") | line.startswith("Error"):
res = re.split(':|=',line)
print(res)
Output which I am getting is
['customer1', '123\n']
['Error', '1\n']
['customer1', '124\n']
['Error', '2\n']
['customer1', '125\n']
['Error', '3\n']
['customer1', '126\n']
['Error', '4\n']