Dear Monks,
I have a directory with several hundred sets of files (an input, data and output file). The files all begin with a given prefix and have a 4 digit sequential number. i.e.
Kick0000.inp
Kick0000.data
Kick0000.log
are the input, data and output files respectively.
I wish to delete the data files of jobs that did not terminate normally (i.e. jobs where the output does not end in "Normal termination").
The following script, using backticks works, but I'm not sure I've done it in the best way. Mainly, I'm concerned about using backticks twice each iteration.
I'd appreciate any advice on whether the backticks really are a problem, and if so, how I could better write this script.
Thanks in advance,
Madd
#!/usr/bin/perl -s
$prefix="Kick";
$Restart="Restart.data";
open (RESTART,"$Restart") or die "Unable to open $Restart for reading\
+n";
$AlreadyDone = <RESTART>;
$jobs_run= sprintf '%04d',($AlreadyDone);
for (my $j=0;$j<=$jobs_run;$j++)
{
$job_no=sprintf '%04d',($j);
$job_title="$prefix$job_no";
$job_end=`tail -n 1 $job_title.log`;
if($job_end !~ /Normal/)
{
`rm $job_title.data`;
}
}