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..
8 Réponses
+ 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
+ 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()
+ 1
hope this will help you
if you have anything doubt with this program you can ask
+ 1
that is in my laptop if you dont mind give your email address i will send you
0
maybe this link will help
https://docs.python.org/2/library/csv.html
0
I want to extract information from log file.. how to do that..
0
can you give me an example with log file and code.. just sample one
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..