最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)掃描日志關(guān)鍵字的示例

 更新時(shí)間:2018年04月28日 14:40:56   作者:大繁至簡(jiǎn)  
下面小編就為大家分享一篇python實(shí)現(xiàn)掃描日志關(guān)鍵字的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

我們?cè)趬毫y(cè)試過(guò)程會(huì)收集到很多l(xiāng)og,怎樣快速?gòu)闹姓业接杏眯畔⒛??讓python腳本幫我們做這部分工作吧!

廢話不說(shuō),上代碼

環(huán)境:win10 + python2.7.14

#-*- encoding: utf-8 -*-
#author : beihuijie
#version 1.1
import re
import sys
import os
import countTime
def getParameters():
 '''
 get parameters from console command
 '''
 with open(sys.argv[1], "r") as fread:
 lines = fread.readlines()
 keywords=[]
 for line in lines:
  temp = line.split(', ')
  keywords.append(temp)
 for i in range(0, (len(keywords[0]) - 1)):
  print ' Keyword = %s' % keywords[0][i]
 return keywords[0]
def isFileExists(strfile):
 '''
 check the file whether exists
 '''
 return os.path.isfile(strfile)
def Search(keyword, filename):
 '''
 search the keyword in a assign file
 '''
 if(isFileExists(filename) == False):
 print 'Input filepath is wrong,please check again!'
 sys.exit()
 linenum = 1
 findtime = 0
 with open(filename, 'r') as fread:
 lines = fread.readlines()
 for line in lines:
  rs = re.findall(keyword, line, re.IGNORECASE)
  if rs:
  #output linenum of keyword place 
  sys.stdout.write('line:%d '%linenum)
  lsstr = line.split(keyword)
  strlength = len(lsstr)
  findtime = findtime + 1
  #print strlength
  for i in range(strlength):
   if(i < (strlength - 1)):
   sys.stdout.write(lsstr[i].strip())
   sys.stdout.write(keyword)
   else:
   sys.stdout.write(lsstr[i].strip() + '\n')
  linenum = linenum + 1
 print '+----------------------------------------------------------------------------+'
 print (' Search result: find keyword: %s %d times'%(keyword, findtime))
 print '+----------------------------------------------------------------------------+'
def executeSearch():
 '''
 this is a execute search method
 '''
 ls = getParameters()
 start = countTime.getTime()
 parameter_number = len(ls)
 print 'Filename = %s ' % ls[parameter_number - 1]
 print '--------------------start search-------------------------'
 if(parameter_number >= 2):
 for i in range(parameter_number - 1):
  Search(ls[i], ls[parameter_number - 1])
 else:
 print 'There is a parameter error occured in executeSearch()!'
 end = countTime.getTime()
 print '+----------------------------------------------------------------------------+'
 print ' Total cost time: %s'%countTime.formatTime(end - start)
 print '+============================================================================+'
 
if __name__=='__main__':
 executeSearch()

countTime.py

#-*- encoding: utf-8 -*-
#author : beihuijie
#version 1.1
import datetime
import time
def getTime():
 '''
 return time is format of time(unit is second)
 '''
 return time.time()
def getCPUClockTime():
 '''
 return time is CPU Clock time
 '''
 return time.clock()
def formatTime(timevalue):
 '''
 format the time numbers
 '''
 hour = 0
 minute = 0
 second = 0
 if timevalue > 0:
 #count hour
 hour = timevalue // 3600
 remain = timevalue % 3600
 #count minute
 minute = remain // 60
 remain = remain % 60
 #count second
 second = round(remain, 3)
 return '%.0fh:%.0fm:%.3fs'%(hour, minute, second)
 
if __name__=='__main__':
 value = 134.45632
 print value
 print formatTime(value)
 

關(guān)鍵字及被掃描的日志路徑信息,記錄到文件中,以逗號(hào)+空格隔開,如,“, ”日志路徑信息放到最后。

格式如下:

anr, dalvikvm: Could not find class 'android.app.usage., panic, C:\Users\BHJ\logcat1.log

執(zhí)行結(jié)果:

以上這篇python實(shí)現(xiàn)掃描日志關(guān)鍵字的示例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python argparse中的action=store_true用法小結(jié)

    Python argparse中的action=store_true用法小結(jié)

    這篇文章主要介紹了Python argparse中的action=store_true用法小結(jié),本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-02-02
  • Python獲取C++中返回的char*字段的兩種思路

    Python獲取C++中返回的char*字段的兩種思路

    有時(shí)候需要獲取C++函數(shù)中返回來(lái)的不定長(zhǎng)的char*字符串,本文小編為大家找到了兩種解決問(wèn)題的思路,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-04-04
  • 深入分析Python中Lambda函數(shù)的用法

    深入分析Python中Lambda函數(shù)的用法

    lambda函數(shù)是Python中常用的內(nèi)置函數(shù),又稱為匿名函數(shù)。和普通函數(shù)相比,它只有函數(shù)體,省略了def和return,使得結(jié)構(gòu)看起來(lái)更精簡(jiǎn)。本文將詳細(xì)說(shuō)說(shuō)Lambda函數(shù)的用法,需要的可以參考一下
    2022-12-12
  • Python腳本/代碼的幾種常見運(yùn)行方式

    Python腳本/代碼的幾種常見運(yùn)行方式

    我們知道,python腳本或者說(shuō)python程序其實(shí)是一個(gè)包含了python代碼的文件,通過(guò)運(yùn)行python代碼,我們可以驗(yàn)證腳本/程序是否按照我們的期望執(zhí)行,在python中,有多種方式來(lái)運(yùn)行腳本或程序,取決于小伙伴們的需求,接下來(lái)小編將介紹幾種常見的 python 代碼運(yùn)行方式
    2023-10-10
  • 使用TensorFlow對(duì)圖像進(jìn)行隨機(jī)旋轉(zhuǎn)的實(shí)現(xiàn)示例

    使用TensorFlow對(duì)圖像進(jìn)行隨機(jī)旋轉(zhuǎn)的實(shí)現(xiàn)示例

    這篇文章主要介紹了使用TensorFlow對(duì)圖像進(jìn)行隨機(jī)旋轉(zhuǎn)的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-01-01
  • Python實(shí)現(xiàn)批量下載音效素材詳解

    Python實(shí)現(xiàn)批量下載音效素材詳解

    制作視頻的時(shí)候,多少需要一些搞怪的聲音?或者奇怪的聲音?音樂(lè)等等。一個(gè)個(gè)下載多慢,我們今天就用python實(shí)現(xiàn)批量下載!需要的可以參考一下
    2022-02-02
  • 解析python的局部變量和全局變量

    解析python的局部變量和全局變量

    函數(shù)內(nèi)部定義的變量就叫局部變量而如果一個(gè)變量既能在一個(gè)函數(shù)中使用,也可以在其他函數(shù)中使用,這樣的變量就是全局變量。 本文給大家介紹python的局部變量和全局變量的相關(guān)知識(shí),感興趣的朋友一起看看吧
    2019-08-08
  • Python中 CSV格式清洗與轉(zhuǎn)換的實(shí)例代碼

    Python中 CSV格式清洗與轉(zhuǎn)換的實(shí)例代碼

    這篇文章主要介紹了Python123 CSV格式清洗與轉(zhuǎn)換的實(shí)例代碼,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-08-08
  • Python中HMAC加密算法的應(yīng)用

    Python中HMAC加密算法的應(yīng)用

    HMAC?算法可用于驗(yàn)證在應(yīng)用程序之間傳遞或存儲(chǔ)在潛在易受攻擊位置的信息的完整性,因此本文為大家整理了一些Python中HMAC加密算法的應(yīng)用,希望對(duì)大家有所幫助
    2023-05-05
  • Python queue模塊攻略全解

    Python queue模塊攻略全解

    這篇文章主要為大家介紹了Python queue模塊攻略全解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-12-12

最新評(píng)論

南陵县| 乐都县| 英山县| 景德镇市| 平乐县| 长治县| 苗栗市| 荔波县| 象山县| 托克逊县| 化州市| 琼结县| 龙南县| 凯里市| 石柱| 屯留县| 冀州市| 东港市| 齐河县| 泰安市| 德州市| 樟树市| 临颍县| 吉水县| 辽中县| 涞水县| 澜沧| 云林县| 体育| 合作市| 全州县| 罗山县| 集安市| 乌兰县| 青川县| 九台市| 霍林郭勒市| 南岸区| 三门峡市| 勃利县| 囊谦县|