Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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.


Comment on Re: How do I remove blank lines from text files?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://21831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-07-28 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls