#!/usr/bin/perl # A script to sort loads of records based on their date stamp # Author: Ian Hickman use strict; use Time::Local; my %months=( "Jan", 0, "Feb", 1, "Mar", 2, "Apr", 3, "May", 4, "Jun", 5, "Jul", 6, "Aug", 7, "Sep", 8, "Oct", 9, "Nov", 10, "Dec", 11 ); my (@dates, @records); my $current=0; while( ){ my @field=split; $records[$current]=$_; $_=$field[3]; my ($day, $month, $year, $hour, $min, $sec) = /^.(\d\d).(\w+).(\d{4}).(\d\d).(\d\d).(\d\d)/; $month=$months{$month}; my $time=timelocal( $sec, $min, $hour, $day, $month, $year ); $dates[$current]="$time $current"; $current++; } my @newdates = sort by_date @dates; my $i; for( $i=0; $i<$current; $i++ ){ $_=$newdates[$i]; my @s=split; print"$records[$s[1]]"; } sub by_date { my ($asplit, $bsplit); $_=$a; my @temp=split; $asplit=$temp[0]; $_=$b; @temp=split; $bsplit=@temp[0]; if( $asplit < $bsplit ){ return -1; } elsif( $asplit eq $bsplit ){ return 0; } elsif( $asplit > $bsplit ){ return 1; } }