處理日誌檔案

2022-09-17 21:27:18 字數 539 閱讀 9467

#

處理日誌檔案

lst = #

用來裝日誌

f = open('

2019-8

',mode='

r',encoding='

utf-8

')#讀取檔案

first = f.readline().strip().split('

,')#

檔案的第一行是屬性,轉化成列表可迭代提取屬性,當做字典的keys

for line in f:#

for迴圈讀取檔案日誌

dic={}#

建立字典進行對日誌整理

k=line.strip().split('

,')#

將提取的日誌檔案變成列表,便於從中提取value

for i in range(len(first)):#

檔案屬性可根據需求增加

dic[first[i]] = k[i]#

向空字典中加入日誌

放入乙個大列表中

print(lst)

awk處理日誌檔案

split出所需要的那一段文字,可以split多次,下標從1開始 split src,dst,分隔符 將所需要的鍵值對得到,並按 tab 分割,這裡只需要乙個,放在變數中 awk f print 在每個檔案中對2中得到的不同值 還是鍵值對,但鍵是相同的 進行統計 awk end 對3中得到的資料進行...

異常處理 建立日誌檔案

procedure clogfile txt string var tf text sfile string begin sfile recod.log trytry assignfile tf,sfile if not fileexists sfile then rewrite tf else w...

python處理大日誌檔案

coding utf 8 import sys import time class tail def init self,file name,callback sys.stdout.write self.file name file name self.callback callback def f...