Need to convert a logfile that will have some information into a csv format.
Sample Data:
Sample Data:
Output:
Info type: PERSON_NAME; Count: 25
Info type: LOCATION; Count: 25
Info type: CREDIT_CARD_NUMBER; Count: 2
Info type: EMAIL_ADDRESS; Count: 150
Info type: US_VEHICLE_IDENTIFICATION_NUMBER; Count: 20
Info type: MALE_NAME; Count: 13
Info type: LAST_NAME; Count: 85
Info type: DOMAIN_NAME; Count: 150
Info type: SSN; Count: 1000
I need this to be converted in to csv format. I am trying with the below logic but import os import sys import csv ip_file=r"C:\Users\bmunagala\Desktop\Output.log" op_file=ip_file.split(".") print("Opening " + ip_file) f0 = open(ip_file,"r") lstInput = [] for oLine in f0: try: lstLine = oLine.replace("\n","").split("Info type:") except Exception as e: print(e) pass lstInput.append(lstLine) f0.close() fw = open(op_file[0] + ".csv", "w") for oLine in lstInput: szWriteLine = ",".join(oLine) fw.write(szWriteLine + "\n") fw.close()But output is like this
Output:, PERSON_NAME; Count: 25
, LOCATION; Count: 25
, CREDIT_CARD_NUMBER; Count: 2
, EMAIL_ADDRESS; Count: 150
, US_VEHICLE_IDENTIFICATION_NUMBER; Count: 20
, MALE_NAME; Count: 13
, LAST_NAME; Count: 85
, DOMAIN_NAME; Count: 150
, SSN; Count: 1000