SO I am not a perl guru, but I do have some pointers
1. Please use strict; at the top of your script and you will uncover many errors
2. As it stands, even without the above I get warnings
3. You have seemed to have over complicated the script quite a bit (more on this in a minute)
4. Your variable names are very misleading based on what they have stored in them:
Code:
08/13/2012 12:00:00 MSDCMGMGT_SC- MSDC-HIPS-01 Missed
$backup_name $nodename $date1 $date2 $type
To me, only $type makes any sense
5. The reason for your unusual output, apart from the ordering above, is that a Failed entry has 2 additional fields
Code:
08/13/2012 11:00:00 08/13/2012 11:24:29 MSDCTNM_SCHED MSDC-TIVOLI-- Failed
08/13/2012 12:00:00 MSDCMGMGT_SC- MSDC-HIPS-01 Missed
So with a little googling / perldocing I found you could probably go with:
Code:
#!/usr/bin/perl -w
use strict;
open(DATA, "</root/Desktop/BACKUP.TXT") or die "Couldn't open file";
while (<DATA>)
{
chomp;
if( m/(Missed|Failed)\s*$/ )
{
my @fields = split;
if( scalar @fields == 5 )
{
print "$fields[2] $fields[3];;$fields[0] $fields[1];$fields[4]\n";
}
else
{
print "$fields[4] $fields[5];;$fields[0] $fields[1];$fields[6]\n";
}
}
}