Gossamer Forum
Home : General : Perl Programming :

Remove blank lines from a file

Quote Reply
Remove blank lines from a file
Hi

How can I remove any blank lines from a file?
I'd like to do this within a sub in a script.

Cheers


------------------
Col
Quote Reply
Re: Remove blank lines from a file In reply to
open(FILE, "file.txt");
@lines=<FILE>;
close(FILE);

open(FILE, ">new_file.txt");
for (@lines){
unless($_ eq "\n"){
print FILE $_;
}
}
close(FILE);

------------------
Turk Scripts
http://turkiyem.com/turkscripts