I do have a whole bunch of files in a directory and from every file I want to remove the first line (including carriage return). I can read the whole file into an array of s
perl -n -i -e 'print unless $. == 1' myfile
This is similar to stocherilac's answer.
But, in any case (and in all the others answer given!) you are always reading the full file. No way of avoiding that, AFAIK.
Oh the prefered language is Perl.
Sometimes sed
is a better sed
than even perl:
sed -i 1d *
How about
tail +2
in shell?
(edit: in newer Linux you may need tail -n +2
(thank you, GNU! :( ))
use Tie::File qw();
for my $filename (glob 'some_where/some_files*') {
tie my @file, 'Tie::File', $filename or die "Could not open $filename: $!";
shift @file;
}
As pointed out by Schwern, the following does not perform an early exit as I had originally thought it would:
perl -pi -e '$_ = q// and last if $. == 1;' myFile
Seems like one cannot avoid processing the whole file after all.
Try this one liner
perl -pi -e '$_ = "" if ( $. == 1 );' filename
I've used it before, should be all you need.