Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by ahunter (Monk)
on Jul 10, 2000 at 21:42 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://21831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 05:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found