我希望使用正则表达式脚本转换我的 nginx 日志,如下所示:
原始日志:
07.21.99.178 - - [01/Jun/2012:12:06:23 +0530] "GET /api?playSessionId=live_21_bc206d95-113f-4b49-989b-7dff77af51c410.190.217.2111338532565422 HTTP/1.1" 200 71 "-" "Jakarta Commons-HttpClient/3.1"
我希望 playSessionId 作为我使用以下脚本的输出:
#!/usr/bin/env ruby
mon={"Jan" => '01',"Feb" => '02',"Mar" => '03',"Apr" => '04',"May" => '05',"Jun" => '06',"Jul" => '07',"Aug" => '08',"Sep" => '09',"Oct" => '10',"Nov" => '11',"Dec" => '12'}
STDIN.each_line do |line|
if line =~ /([\d+|\.]+) (\d+)\/(\w+)\/(\d+):(\d+):\d+:\d+ \+\d+] "GET \/api\?playSessionId=(^&*)/
d = "#{$3}-#{mon$2}-#{$1}"
h = $4
pid = $5
puts "#{d}\t#{h}\t#{pid}"
end
end
但这似乎不起作用:(有人可以告诉我java正则表达式,以便我可以在hive上起诉rlike吗?