import re import sys import csv import os output=sys.stdout for file in os.listdir("C:/Users/Administrator/Desktop/Data_tidy/log_orig"): with open ("C:/Users/Administrator/Desktop/Data_tidy/log_orig/"+file,‘r‘,encoding=‘UTF-8‘) as f: fileName = re.split(‘\.‘,file) outputfile=open(‘C:/Users/Administrator/Desktop/Data_tidy/ios/‘+fileName[0]+‘.txt‘,‘w‘) #正则表达式体现过滤方式 pattern = re.compile(r‘(.*)(-----cpu)‘) for line in f: m=pattern.match(line) sys.stdout=outputfile if(m is not None): print (line,end = ‘ ‘) outputfile.close() sys.stdout=output
时间: 2024-10-08 00:30:11