#!/usr/bin/perl use strict; use warnings; for my $file(“xsd00544.05”) { open (my $fh,'<',$file) or die "Cant open file $file: $!"; open (my $SORT,">","PSATst1.tab") or die "Can't open sort output file: $!"; my @data; my $server; my $date; my $offset; while (my $line = <$fh> { chomp($line); if (($line =~ /MONTHLY USAGE FOR/) and ($. < 4)) { $offset = index($line,"MONTHLY USAGE FOR"); $date = substr($line,$offset+18,7); $server = substr($line,$offset+30,8); } last if ($line =~ /TOTAL COMMAND SUMMARY/); next unless $line =~ /^\d/; # Only process lines that begin with digits push @data,$line; } my @sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map [ $_, (split)[1] ], @data; print $SORT “$server \t $date \t $_\n” for @sorted; close $fh or die "Cant close file $file: $!"; close $SORT or die "Cant close sorted output file : $!"; }