I have used awk, Python, and Perl to switch logs. I still feel that Perl is a master of log cutting. It has high execution efficiency and powerful functions. Below is a small example:
Open (file, "/data/EBI/META/log ");
Open (Conf, "/data/EBI/CONF/urltype.txt ");
Open (log, ">/data/EBI/META/log_2 ");
@ Array1 = ();
While (<conf> ){
Chomp;
@ Array2 = Split (/,/, $ _);
If (scalar (@ array2)> = 6 ){
Push @ array1, [@ array2];
}
}
Close (CONF );
While (<File>)
{
Chomp;
My ($ SUV, $ times, $ IP, $ URL, $ refer, $ type1) = Split (/\ s +/, $ _);
$ Type = $ type1;
My (UNDEF, UNDEF, $ site) = Split (//, $ URL );
If ($ urlsitemap {$ URL }){
$ Site = $ urlsitemap {$ URL} [0];
$ Prod = $ urlsitemap {$ URL} [1];
$ Fun = $ urlsitemap {$ URL} [2];
}
Else {
For $ I (0 .. $ # array1 ){
$ Regx =@{$ array1 [$ I]} [1];
If ($ url = ~ /$ Regx /){
$ Site =@{$ array1 [$ I]} [2];
$ Prod =@{$ array1 [$ I]} [3];
$ Fun =@{$ array1 [$ I]} [4];
$ Urlsitemap {$ URL} = [$ site, $ prod, $ fun];
Last;
}
}
}
Print log "$ site $ SUV $ IP $ URL $ refer, $ Type \ n ";
}
Close (File );
Close (log );