in reply to Sorting dates and times

The non-trivial part of sorting log files is efficiency, especially when you get into logs that are of any significant size.

If you have small(ish) log files or memory to burn, then a Schwartzian or Guttman-Rossler Transform can make for a short and simple (YMMV :)) script...

#!/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 <UNSORTED>; 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" ); }

    --k.