0

I have log file as,

116.48.29.143 - - [01/Oct/2013:20:28:21 +0530] "GET /test.php HTTP/1.1" 200 749 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"

145.89.87.211 - - [01/Oct/2013:20:28:21 +0530] "GET /test.php HTTP/1.1" 200 613 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"

REGISTER file:/home/hadoop/lib/pig/piggybank.jar;
DEFINE EXTRACT org.apache.pig.piggybank.evaluation.string.EXTRACT();             
DEFINE CustomFormatToISOorg.apache.pig.piggybank.evaluation.datetime.convert.CustomFormatToISO();
DEFINE ISOToUnix org.apache.pig.piggybank.evaluation.datetime.convert.ISOToUnix();
DEFINE DATE_TIME org.apache.pig.piggybank.evaluation.datetime.DATE_TIME();
DEFINE FORMAT_DT org.apache.pig.piggybank.evaluation.datetime.FORMAT_DT();
DEFINE FORMAT org.apache.pig.piggybank.evaluation.string.FORMAT();

A = LOAD 'input' USING TextLoader AS (line:chararray);

B = FOREACH A GENERATE FLATTEN (REGEX_EXTRACT_ALL(line,'^(\\S+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] "(.+?)" (\\S+) (\\S+) "([^"]*)" "([^"]*)"') ) AS (remoteAddr:chararray, remoteLogname: chararray, user: chararray,  time: chararray, request: chararray, status: int, bytes_string: chararray, referrer: chararray, browser: chararray);

My problem is to extract the minutes, i mean from [01/Oct/2013:20:28:21 +0530] i need to get only 28:21

how can i extract that??

4

2 回答 2

0

您已经知道如何编写正则表达式,那么为什么不修改现有的或编写一个新的呢?这是一个新的:

C = FOREACH A GENERATE REGEX_EXTRACT(time, '[\\w/]+:\\d{2}([\\d:]+)\\s[+\\-]\\d{4}') AS hourMin;
于 2013-10-22T11:20:28.907 回答
0

我为这种应用程序编写了一个特殊的 Pig Loader。这允许更轻松地解析 Apache HTTPD 日志文件。

你可以在你的 pig 应用程序中使用它,看起来像这样:

REGISTER httpdlog-pigloader-1.0-SNAPSHOT-job.jar

Clicks = 
  LOAD 'access_log.gz' 
  USING nl.basjes.pig.input.apachehttpdlog.Loader(
    '%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"',
    'IP:connection.client.host',
    'TIME.MINUTE:request.receive.time.minute',
    'HTTP.URI:request.firstline.uri',
    'STRING:request.firstline.uri.query.foo',
    'STRING:request.status.last',
    'HTTP.URI:request.referer',
    'STRING:request.referer.query.foo',
    'HTTP.USERAGENT:request.user-agent')
  AS ( 
    ConnectionClientHost,
    RequestReceiveTimeMinute,
    RequestFirstlineUri,
    RequestFirstlineUriQueryFoo,
    RequestStatusLast,
    RequestReferer,
    RequestRefererQueryFoo,
    RequestUseragent);

你可以在这里下载:https ://github.com/nielsbasjes/logparser

于 2013-10-22T19:27:12.513 回答