Other Ways To Do It (mostly not one-liners) can be found at the thread "How do I remove blank lines from text files?".
Hmmm... personally, I like Ovid's example below better than mine. It *does* seem more directly recognizable.
This snippet removes all non-empty lines containing
only whitespace, but I don't think that's particularly
intuitive behaviour. If I want to remove all "blank"
lines from a file, I probably want:
perl -i.bak -ne 'print if /\S/' file.txt
and if I want to get rid of all the lines with
"useless" whitespace, I probably want to collapse them
to empty lines:
perl -i.bak -ne 's/^\s+$//;print' file.txt
Update: Changed first one-liner
to Ovid's for readability.
Seems a bit more intuitive to me :)
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
-- Chip Salzenberg, Free-Floating Agent of Chaos
Use subroutines for code reuse
Master regular expressions
Write my GUIs with Perl
Abandon CGI in favor of some modern web framework
Put my code in modules
Create CPAN distributions
test and document my code as I write it
Write OOP with or without animal help
Finally switch to a modern Perl style
Create a killer application with Perl
Detoxify from Perl and PerlMonks
Choose another language because Perl is dead
Learn to program for mobile devices
Complete my secret world domination project
None, because the road to hell is paved with good intentions
Results (227 votes),