I'm trying to rename a set of files based on what is in the file itself. I have likely more than a thousand files to rename by the time I'm done. I have code that will get me the first part of the file name, but I need to include other elements in the file name. Here's the first part of the code I am using that I use daily on another task.
# open(INFILE,"list.txt") or die "could not open file for reading!\n";
open(OUTFILE, '>forecast_mips.txt') or die "Cannot open forecast.txt: $!";
my @output;
while(<INFILE>) {
chomp;
next if /^\s*$/;
my @fields = split;
foreach my $field (@fields) {
push @output, $field
if $field =~ /^\*?[ABMQRWY][A-Z0-9]{4}235/;
}
foreach my $field1 (@fields
}
print OUTFILE join("\n", @output), "\n";
print join(@output),"\n";
I'm trying to include two other elements in the file name though. In the file are the Jobname which the above code produces, but I also need the Job Number, a 5 digit number, and the date of the run which will be a 5 digit Julian fixed date. The following is what the file will be based on. The bolded text is what I need in the file name. The date will need to be a Julian date, in this case 22356. So with the below, The filename would be D47YC235#03618-22356. Not sure if there's a better way in retrieving the below items and setting the file name. The if $field =~ line produces the D47YC235 from the file.
00.55.30 JOB03618 ICH70001I $$MP235 LAST ACCESS AT 00:55:30 ON THURSDAY, **DECEMBER 22, 2022**
00.55.30 JOB**03618** $HASP373 **D47YC235** STARTED - INIT 39 - CLASS R - SYS V4YM
**
characters just your annotations indicating what text you are scraping from the file?