R
rsarpi
using perl 5.8.8
Objective: remove last 10 lines of *all* files in a directory with no
branches.
Like...xfiles directory has the files xfile1...xfile10. No
subdirectories. I want to remove the last 10 lines of xfile1...xfile10.
How do I do that?
I've tried to put all files in an array but I can't open all files at
one to write to them. And for some reason globbing doesn't do the
trick...like glob ("*.*");
I came up with something to delete the last 10 lines of ONE file only.
(A portion of this code is mine the other is from the perl cookbook)
----------
#!/usr/bin/perl
use warnings;
use strict;
my $path = "C:/path/to/file.txt";
my $addr = "";
#create a sentinel value
my $counter = 1;
#kicks out after it reaches line 10. We just want to delete 10 lines
while ( $counter <= 10 ) {
open( FH, "+< $path" ) or die $!;
while (<FH>) {
$addr = tell(FH) unless eof(FH);
}
truncate( FH, $addr ) or die $!;
#update sentinel value
$counter++;
}
print "all done\n";
Objective: remove last 10 lines of *all* files in a directory with no
branches.
Like...xfiles directory has the files xfile1...xfile10. No
subdirectories. I want to remove the last 10 lines of xfile1...xfile10.
How do I do that?
I've tried to put all files in an array but I can't open all files at
one to write to them. And for some reason globbing doesn't do the
trick...like glob ("*.*");
I came up with something to delete the last 10 lines of ONE file only.
(A portion of this code is mine the other is from the perl cookbook)
----------
#!/usr/bin/perl
use warnings;
use strict;
my $path = "C:/path/to/file.txt";
my $addr = "";
#create a sentinel value
my $counter = 1;
#kicks out after it reaches line 10. We just want to delete 10 lines
while ( $counter <= 10 ) {
open( FH, "+< $path" ) or die $!;
while (<FH>) {
$addr = tell(FH) unless eof(FH);
}
truncate( FH, $addr ) or die $!;
#update sentinel value
$counter++;
}
print "all done\n";