0

How to extract information from log file in python?

I have log file I want to write into csv with particular set of columns but I don't know how to write it can anyone help me..

27th Feb 2018, 7:45 AM
susmitha
susmitha - avatar
8 Answers
+ 2
first open that log file in read mode the iterate each row then split the informations which you want to store in csv file and store that in csv format
27th Feb 2018, 9:11 AM
sushant gupta
sushant gupta - avatar
+ 1
import csv logFile = open("logfile.log" ,"r") with open('csvfile.csv' ,'w') as f: #columns in which you want to store csv data fieldnames = ['col1' ,'col2' ,'col3' ,'col4'] writer.csv.DictWriter(f, fieldnames =fieldnames) writer.writeheader() for row in logFile: r = row.split(' ') writer.writerow({'col1' : r[0] ,'col2': r[1] ,'col3' :r[2] ,'col4' : r[3]}) #here you can also concatinate several data which is stored in r logFile.close()
27th Feb 2018, 2:50 PM
sushant gupta
sushant gupta - avatar
+ 1
hope this will help you if you have anything doubt with this program you can ask
27th Feb 2018, 2:51 PM
sushant gupta
sushant gupta - avatar
+ 1
that is in my laptop if you dont mind give your email address i will send you
27th Feb 2018, 2:55 PM
sushant gupta
sushant gupta - avatar
0
maybe this link will help https://docs.python.org/2/library/csv.html
27th Feb 2018, 8:57 AM
sushant gupta
sushant gupta - avatar
0
I want to extract information from log file.. how to do that..
27th Feb 2018, 8:59 AM
susmitha
susmitha - avatar
0
can you give me an example with log file and code.. just sample one
27th Feb 2018, 10:45 AM
susmitha
susmitha - avatar
0
can you give me log file please... because I want to see how log file looks and how you can program it and which output comes... please don't mind that I am asking questions..
27th Feb 2018, 2:54 PM
susmitha
susmitha - avatar