Log processing 1

Task:Every three rows of records are a piece of log. Organize the log into a structured file.

Python

1 import pandas as pd
2 import numpy as np
3 log_file = 'E://txt//access_log.txt'
4 log_info = pd.read_csv(log_file,header=None)
5 log_g=log_info.groupby(log_info.index//3)
6 rec_list = []
7 for i,g in log_g:
8     rec = g.values.reshape(1*3)
9     rec[1] = rec[1].split(":")[-1].replace("#","")
10     rec="\t".join(rec)
11     rec = np.array(rec.split("\t"))
12     rec = rec[[6,7,0,1,3,4,8,5]]
13     rec_list.append(rec)
14 rec_df = pd.DataFrame(rec_list,columns=["USERID","UNAME","IP","TIME","URL","BROWER","LOCATION","module"])
15 print(rec_df)

esProc

  A  
1 E://txt//access_log.txt  
2 =file(A1).import@s()  
3 =A2.group((#-1)\3)  
4 =A3.(~.(_1).concat("\t").array("\t"))  
5 =A4.new(~(7):USERID,~(8):UNAME,~(1):IP,~(2):TIME,~(4):URL,~(5):BROWER,~(9):LOCATION,left(~(6).array("\:")(2),-1):module)  

With the mechanism of grouping by row number, you can process one group of data every time in loop, simplifying the difficulty.