YouEnjoyMyself
IS-IT--Management
Hello,
I am writing a script that parses a log file into an excel spread sheet (.csv). The sample input (posted below) ends up giving me 24 different entries for each field requested to be parsed. Go ahead and run it you will get a better idea of what I mean. I would greatly appreciate any help, This forum has been a great help to me in the past. Thank you in advance! I have attached the script and a sample input below:
#This program will report the tapes created within the last 875 hours
#!/opt/nokianms/bin/perl
#opens bpimagelist.cmd
$DATA= "C:\\vmquery.txt";
open (DATA, "$DATA") or die "Can't open $DATA: $!\n";
#opens Tapelog.txt (Data)
open(CSVFILE, ">C:\\vmquery.csv") || die qq(Can't open "vmquery.csv " for output.\n);
#creates Tapes_To_Be_Pulled.csv (output file)
print CSVFILE "Media ID,Volume Pool,Date Created,Date Assigned,Expiration Date,status\n";
#Below parses Tapelog.txt for the listed fields
while (<DATA>) {
chomp;
s{s*\d+:\d+:\d+\s*\)
}{}x; #Takes C time off of the Media Date listing, or any other time listing in logfile.
$_=~ s/^\s+//; $_ =~ s/\s+$//;
my ($key, $value) = ($_=~ m!(.+): (.+)!);
$value =~ s/^\s+//; $value =~ s/\s+$//;
print "$key,$value\n";
$mediaid = $value if (/^media ID/);
$volumepool = $value if (/^volume pool/);
$created = $value if (/^created:/);
$assigned= $value if (/^assigned:/);
$expirationdate = $value if (/^expiration date:/);
$status = $value if (/^status/);
print CSVFILE "$mediaid,$volumepool,$created,$assigned,$expirationdate,$status\n";
}
close(CSVFILE) || die qq(Can't close input file "Tapelog.txt".\n);
close(DATA) || die qq(Can't close output file "Tapes_To_Be_Pulled.csv".\n);
Sample input:
================================================================================
media ID: 000724
media type: 1/2" cartridge tape (6)
barcode: 000724
media description: ---
volume pool: Samples (59)
robot type: NONE - Not Robotic (0)
volume group: ---
vault name: ---
vault sent date: ---
vault return date: ---
vault slot: ---
vault session id: ---
vault container id: -
created: 10/7/2002 9:47:48 AM
assigned: 12/14/2003 8:10:03 PM
last mounted: 12/14/2003 8:11:03 PM
first mount: 10/8/2002 6:56:18 PM
expiration date: ---
number of mounts: 51
max mounts allowed: ---
status: 0x0
=
I am writing a script that parses a log file into an excel spread sheet (.csv). The sample input (posted below) ends up giving me 24 different entries for each field requested to be parsed. Go ahead and run it you will get a better idea of what I mean. I would greatly appreciate any help, This forum has been a great help to me in the past. Thank you in advance! I have attached the script and a sample input below:
#This program will report the tapes created within the last 875 hours
#!/opt/nokianms/bin/perl
#opens bpimagelist.cmd
$DATA= "C:\\vmquery.txt";
open (DATA, "$DATA") or die "Can't open $DATA: $!\n";
#opens Tapelog.txt (Data)
open(CSVFILE, ">C:\\vmquery.csv") || die qq(Can't open "vmquery.csv " for output.\n);
#creates Tapes_To_Be_Pulled.csv (output file)
print CSVFILE "Media ID,Volume Pool,Date Created,Date Assigned,Expiration Date,status\n";
#Below parses Tapelog.txt for the listed fields
while (<DATA>) {
chomp;
s{s*\d+:\d+:\d+\s*\)
}{}x; #Takes C time off of the Media Date listing, or any other time listing in logfile.
$_=~ s/^\s+//; $_ =~ s/\s+$//;
my ($key, $value) = ($_=~ m!(.+): (.+)!);
$value =~ s/^\s+//; $value =~ s/\s+$//;
print "$key,$value\n";
$mediaid = $value if (/^media ID/);
$volumepool = $value if (/^volume pool/);
$created = $value if (/^created:/);
$assigned= $value if (/^assigned:/);
$expirationdate = $value if (/^expiration date:/);
$status = $value if (/^status/);
print CSVFILE "$mediaid,$volumepool,$created,$assigned,$expirationdate,$status\n";
}
close(CSVFILE) || die qq(Can't close input file "Tapelog.txt".\n);
close(DATA) || die qq(Can't close output file "Tapes_To_Be_Pulled.csv".\n);
Sample input:
================================================================================
media ID: 000724
media type: 1/2" cartridge tape (6)
barcode: 000724
media description: ---
volume pool: Samples (59)
robot type: NONE - Not Robotic (0)
volume group: ---
vault name: ---
vault sent date: ---
vault return date: ---
vault slot: ---
vault session id: ---
vault container id: -
created: 10/7/2002 9:47:48 AM
assigned: 12/14/2003 8:10:03 PM
last mounted: 12/14/2003 8:11:03 PM
first mount: 10/8/2002 6:56:18 PM
expiration date: ---
number of mounts: 51
max mounts allowed: ---
status: 0x0
=