in reply to Re: truncate only a last blank line
in thread truncate only a last blank line

Thank you so much for your reply.
I really don't know how to thank you enough!
This script did exactly what I needed to do.
I modified it a little bit at the end.
Thank you again!

#! usr/bin/perl opendir(FILES,".")||die "Cannot open files in the directory\n"; @files=(); for(readdir(FILES)){ if($_=~/\.txt/){ push(@files, $_); } } print "@files\n"; for $i(0..$#files){ print "working on $files[$i]\n"; open (FH, "+<$files[$i]") or die "can't update $file: $!"; my $linevalue; while ( $linevalue = <FH> ) { $addr = tell(FH) unless eof(FH); last if (eof(FH)); } if($linevalue =~ /^\s*$/) { truncate(FH, $addr) or die "can't truncate $file: $!"; print "truncated the last blank line in $files[$i]\n"; }else{ print "$files[$i] does not end with blank line\n"; } } exit;