#!/util/bin/perl # The sort command won't work because of poor sort keys. This is a smart # sort replacement. open(IN, $ARGV[0]); open(OUT, "> $ARGV[1]"); # sort the records by trnumber sub trsort { my($p, $q); $a =~ /\[(\d+-\d+)\]/; $p = $1; if (substr($p, 0, 2) ne '20') { $p = '19' . $p; } $b =~ /\[(\d+-\d+)\]/; $q = $1; if (substr($q, 0, 2) ne '20') { $q = '19' . $q; } return $p cmp $q; } @a = ; foreach (reverse sort trsort @a) { print OUT; }