S
Shawn
Hello,
I am very novice as you will see in my Perl skills. I thought I'd write a
simple script to rename a list of files in a directory
based on some validation checks. The first checking if the file is empty
and the 2nd checking if there is the character /
in a certain position in the file. The script is below
My first problem when I was testing this was the script seeing the file with
data even though I had created a zero byte file.
So, regardless of the file size it found it with data. Which leads me to
believe I'm not checking the file size correctly.
The second problem being the renaming of the file. I am receiving a
insufficient arguments error which has stumped me.
In this case, I'm guessing maybe I have a error in the FILE_LIST?
Any suggestions would be greatly appreciated.
Thanks.
#!/usr/local/bin/perl5.6
use lib "lib";
use MIME::Lite;
open(FILE_LIST,"ls f* | grep -v txt|" ) || die "Cannot do \n" ;
while ($cfile = <FILE_LIST>) {
if ( -z "$cfile" ) {
system("/bin/mv $cfile $cfile.zero.txt");
print "$cfile has zero data\n";
}
else {
print "$cfile has data\n";
}
$charcount = system("cut -c9 $cfile |sort -u |grep '/'
|wc -l");
if ( $charcount > 0 ) {
chomp($csv_client_id = `cut -c1-6 $cfile |sort -u`);
print "character found for $cfile"\n" ;
system("/bin/mv $cfile
${cfile}.char.txt");
else {
system("/bin/mv $cfile
${cfile}.nochar.txt");
}
}
I am very novice as you will see in my Perl skills. I thought I'd write a
simple script to rename a list of files in a directory
based on some validation checks. The first checking if the file is empty
and the 2nd checking if there is the character /
in a certain position in the file. The script is below
My first problem when I was testing this was the script seeing the file with
data even though I had created a zero byte file.
So, regardless of the file size it found it with data. Which leads me to
believe I'm not checking the file size correctly.
The second problem being the renaming of the file. I am receiving a
insufficient arguments error which has stumped me.
In this case, I'm guessing maybe I have a error in the FILE_LIST?
Any suggestions would be greatly appreciated.
Thanks.
#!/usr/local/bin/perl5.6
use lib "lib";
use MIME::Lite;
open(FILE_LIST,"ls f* | grep -v txt|" ) || die "Cannot do \n" ;
while ($cfile = <FILE_LIST>) {
if ( -z "$cfile" ) {
system("/bin/mv $cfile $cfile.zero.txt");
print "$cfile has zero data\n";
}
else {
print "$cfile has data\n";
}
$charcount = system("cut -c9 $cfile |sort -u |grep '/'
|wc -l");
if ( $charcount > 0 ) {
chomp($csv_client_id = `cut -c1-6 $cfile |sort -u`);
print "character found for $cfile"\n" ;
system("/bin/mv $cfile
${cfile}.char.txt");
else {
system("/bin/mv $cfile
${cfile}.nochar.txt");
}
}