Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How do I remove blank lines from text files?

by ahunter (Monk)
on Jul 10, 2000 at 21:42 UTC ( #21831=note: print w/replies, xml ) Need Help??


in reply to How do I remove blank lines from text files?

(This will take input from STDIN and go to STDOUT). Depends on how you define blank lines. If you just want to remove lines that contain absolutely nothing, this will do the trick:
while (<STDIN>) { print if (!/^$/); }
^ and $ are anchors and indicate the start and end of the current record (which will be the current line with the default record seperator). If you mean to delete lines that only contain whitespace, this will do the trick:
while (<STDIN>) { print if (!/^\s*$/); }
(\s is the whitespace character, and includes newlines, spaces and tabs)

Andrew.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://21831]
help
Chatterbox?
and snow settles gently...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2016-12-03 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (52 votes). Check out past polls.