__author__ = ‘Administrator‘ import xlsxwriter as writer import xlrd as read import linecache import re CPUFile=‘jcc.txt‘ CPUfiles=[‘jcc.txt‘,‘jcc2.txt‘] def getKeyline(CPUFile): Keyline=0 fin=open(CPUFile,‘r‘) KeyLine=[] for num,line in enumerate(fin): if "sh 30" in line: Keyline=str(num) #print "Keyline="+Keyline if "pool used size" in line and Keyline>0: KeyLine.append(num+1) if "T_TREE" in line and Keyline>0: KeyLine.append(num+1) if "B_TREE" in line and Keyline>0: KeyLine.append(num+1) if "U_WMCINFO" in line and Keyline>0: KeyLine.append(num) return KeyLine def Getkeyword(Filenum,Theline): workbook = writer.Workbook(‘jcc2.xls‘) worksheet = workbook.add_worksheet(‘Cpuinfo‘) #p=re.compile(r"(\:)\d+B|( )\d+ ") print Theline, if "T_TREE" in Theline: p=re.compile(r"(\:)\d+B") for m in p.finditer(Theline): print m.group() print Filenum worksheet.write(Filenum, 2, m.group()) if "B_TREE" in Theline: p=re.compile(r"(\:)\d+B") for m in p.finditer(Theline): worksheet.write(Filenum, 3, m.group()) if "pool used size" in Theline: p=re.compile(r"( )\d+ ") for m in p.finditer(Theline): worksheet.write(Filenum, 1, m.group()) workbook.close() def main(): for j in CPUfiles: x=1 for i in getKeyline(j): Theline=linecache.getline(j,i) Getkeyword(x,Theline) x=x+1 #print Theline if __name__=="__main__": main()
时间: 2024-10-21 13:31:11