Skip to content

Instantly share code, notes, and snippets.

Created May 1, 2015 21:32
Show Gist options
  • Save anonymous/50d280dc1acd90067007 to your computer and use it in GitHub Desktop.
Save anonymous/50d280dc1acd90067007 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'date'
session = Hash.new
time = Array.new
parseapache = /.*\[(.*) .*\].* ([a-zA-Z0-9]+)$/
File.open("test100").each do |line|
matches = parseapache.match(line)
if matches
if !(session[matches[2]])
session[matches[2]] = Array.new
session[matches[2]] << DateTime.strptime(matches[1], "%d/%b/%Y:%H:%M:%S").to_s
session[matches[2]].sort
else
session[matches[2]] << DateTime.strptime(matches[1], "%d/%b/%Y:%H:%M:%S").to_s
session[matches[2]].sort
end
end
end
overall = 0
sessions = 0
session.each do |key, value|
puts "#{key} = #{value}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment