#!/usr/bin/perl -w use strict; use Time::Piece; die "$0 [input] [output]\n" unless @ARGV; die "Input/output can't match\n" if $ARGV[0] eq $ARGV[1]; open UNSORTED, "< $ARGV[0]" or die "Can't open $ARGV[0] for reading: $!\n"; open SORTED, "> $ARGV[1]" or die "Can't open $ARGV[1] for writing: $!\n"; print SORTED map { $_->[1] } # restore data to original form sort { $a->[0] <=> $b->[0] } # sort by time/date map { [ epoch_date(), $_ ] } # prepend time/date as secs ; sub epoch_date { # Convert Apache style-dates to epoch seconds return unless /^\S+ \S+ \S+ (\S+)/; return Time::Piece->strptime( $1, "[%d/%b/%Y:%T" ); }