Here is a relatively simple generic solution to be tailored to your specific requirements. I've named it headtail.pl but you can call it whatever you want.
#!/usr/bin/perl -Tw use strict; use warnings; my $skiphead = 1; my $skipfoot = 2; my $infile = 'test.txt'; my $outfile = '/tmp/out.txt'; my @buffer = (); open IN, '<', $infile or die "Cannot open $infile for reading: $!"; open OUT, '>', $outfile or die "Cannot open $outfile for writing: $!"; <IN> for (1..$skiphead); push @buffer, scalar <IN> for (1..$skipfoot); while (<IN>) { print OUT shift @buffer; push @buffer, $_; } close OUT; close IN;
$ cat test.txt 1 hello 2 there 3 this 4 is 5 a 6 good 7 test $ ./headtail.pl $ cat out.txt 2 there 3 this 4 is 5 a
In reply to Re: Deleting first and last lines of a text file
by hippo
in thread Deleting first and last TWO(2) lines of a text file
by vsmeruga
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |