in reply to Re^5: Deleting first and last lines of a text file
in thread Deleting first and last TWO(2) lines of a text file
Thanks for your time. I tried with below code. but it deleted just first line. Can you please help me to delete last 2 lines as well
#!/usr/bin/perl use strict; use warnings; my $file='tgtfile.txt'; open STDOUT, ">", $file or die "$0: open: $!"; open STDERR, ">&STDOUT" or die "$0: dup: $!"; my $filename = 'srcfile_20140319.txt'; # specify the file name here open my $fh, '<', $filename or die "can't open $filename: $! "; while ( defined( $_ = <$fh> ) ) { print $_ unless $. == 1 or eof; } close $fh or die "can't close $filename: $!";
|
|---|