my $filename = 'DMEP.A0PD7193.DMECBID.SUPL.2011042981697.txt';
What's the alternative for this?
The perl script should go inside the folder
/etl/foldername/
and look for the file (In this case, it should be file pattern matching).
and then load the file...
The script that i am using and which does not find file is
#!/usr/bin/perl -w
$file = '/etl/PDAC/CBA/Supplier/';
$filepattern = '.*A0PD7193.*DMECBID.SUPL.*\.txt';
if ($file =~ $filepattern){
print "The file is there and now the Job load begins\n";
}else {
print "The file does not exist.\n";
}
exit;
This is the result. But the file does exist in the folder..
-bash-3.00$ ./Supplier_filecheck_andload_test1.pl
The file does not exist.
If you want to list all files matching the pattern under /etl/PDAC/CBA/Supplier/, use the following script:
#!/usr/bin/perl
use strict;
use warnings;
opendir(DIR, "/etl/PDAC/CBA/Supplier/") or die "Failed.";
my @files = grep(/.*A0PD7193.*DMECBID.SUPL.*\.txt/, readdir DIR);
foreach my $f (@files) {
print "$f\n"
}
You can also use bash:
#!/bin/bash
for f in `find /etl/PDAC/CBA/Supplier -maxdepth 1 -type f`; do
if [ x`echo "$f" | grep '.*A0PD7193.*DMECBID.SUPL.*\.txt'` != "x" ]; then
echo "The file is there and now the Job load begins."
else
echo "The file does not exist."
fi
done