#!/usr/bin/env ruby require 'date' require File.expand_path("../lib/log_slice", File.dirname(__FILE__)) if ARGV.length < 2 $stderr.puts "USAGE: #{$0} DATE [END_DATE] FILEPATH\n\n" $stderr.puts "EXAMPLE: #{$0} '2012-08-31 12:00:00' /tmp/something.log\n" $stderr.puts "EXAMPLE: #{$0} '2012-08-31 12:00:00' '2012-08-31 12:05:00' /tmp/something.log\n" $stderr.puts "Expects log lines to contain a DateTime string enclosed in [square brackets] \n\n" end start_date = ARGV[0] (end_date, file) = begin if ARGV.length == 2 [nil, ARGV[1]] else [ARGV[1], ARGV[2]] end end begin LogSlice::DateRange.new(file, start_date, end_date).each do |line| puts line end rescue Errno::EPIPE end