Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: How do I remove the first line of a file without reading and copying whole file

Tags:

People also ask

How do I skip a line while reading a file in perl?

To skip over blanks lines in a perl script, you have several choices. You could use a "next if /^$/" (skip if empty) command or a "next if /^\s*$/" skip if empty or only white space.

How do I print the first line of a file in perl?

Solution: Read in the first line, do your processing, then continue reading the file. #!/usr/bin/perl -w use strict; use warnings; my $file = "..."; open (CODE, $file) || die "Couldn't open $file: $!"; print scalar <CODE>; # Print the first line # ... Do your processing here ...

How do I print the last line of a file in perl?

open(FILE,'file. txt'); while (<FILE>) print if eof; } close(FILE);


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 strings and write all but the first element to a new file, but that looks a bit cumbersome to me are there better ways? Oh the prefered language is Perl.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!