Parsing amazon s3 log files (PHP) -
i'm looking parse amazon s3 log files space delimited. problem is, of space delimited fields contain spaces. how go parsing file this?
450227804f8fd31c931036b020ddd0003a03b421d8c669d8858c7c15d72c renderd [10/apr/2014:19:32:23 +0000] 75.256.56.200 450227804f8fd31c931036b020000343afa03b421d8c669d8858c7c15d72c 0231400aa3d3533c rest.get.object trailer.mp4 "get /trailer.mp4?awsaccesskeyid=akiajfv33yrqmn63aqcq&expires=1397159234&signature=8ipn9ymsb5gczxchtu9ld6zmrda%3d http/1.1" 206 - 5016183 16149754 216682 39 "http://example.com" "mozilla/5.0 (macintosh; intel mac os x 10_9_2) applewebkit/537.36 (khtml, gecko) chrome/33.0.1750.152 safari/537.36" -
you use regular expression parse log file various parts
here example in php that
<?php $string ='450227804f8fd31c931036b020ddd0003a03b421d8c669d8858c7c15d72c renderd [10/apr/2014:19:32:23 +0000] 75.256.56.200 450227804f8fd31c931036b020000343afa03b421d8c669d8858c7c15d72c 0231400aa3d3533c rest.get.object trailer.mp4 "get /trailer.mp4?awsaccesskeyid=akiajfv33yrqmn63aqcq&expires=1397159234&signature=8ipn9ymsb5gczxchtu9ld6zmrda%3d http/1.1" 206 - 5016183 16149754 216682 39 "http://example.com" "mozilla/5.0 (macintosh; intel mac os x 10_9_2) applewebkit/537.36 (khtml, gecko) chrome/33.0.1750.152 safari/537.36" -'; $pattern = '/(?p<owner>\s+) (?p<bucket>\s+) (?p<time>\[[^]]*\]) (?p<ip>\s+) (?p<requester>\s+) (?p<reqid>\s+) (?p<operation>\s+) (?p<key>\s+) (?p<request>"[^"]*") (?p<status>\s+) (?p<error>\s+) (?p<bytes>\s+) (?p<size>\s+) (?p<totaltime>\s+) (?p<turnaround>\s+) (?p<referrer>"[^"]*") (?p<useragent>"[^"]*") (?p<version>\s)/'; preg_match($pattern, $string, $matches); print_r($matches);
Comments
Post a Comment