Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: replace multiple newline characters

by hippo (Bishop)
on May 15, 2018 at 08:15 UTC ( [id://1214527]=note: print w/replies, xml ) Need Help??


in reply to Re: replace multiple newline characters
in thread replace multiple newline characters

Provided your input-file is small enough to be read into memory

Here's one without that constraint:

perl -i.old -ne 'print if /./;' input.txt

Replies are listed 'Best First'.
Re^3: replace multiple newline characters
by haukex (Archbishop) on May 15, 2018 at 09:48 UTC

      Shorter, yes, but it looks like you've re-introduced the "input-file is small enough to be read into memory" constraint. Or have I missed something?

        Shorter, yes, but it looks like you've re-introduced the "input-file is small enough to be read into memory" constraint. Or have I missed something?

        Hm, good point, I guess in my excitement over the nice short oneliner I sort of did. -000* turns on paragraph mode, so if the file contains lots of short "paragraphs" with blank lines in between, it'll be fine, but if the file contains, say, a block of several MB of non-blank lines, a single blank line, and another huge paragraph, then yes, you're right, my solution isn't that great.

        * perlrun is a little unclear whether it's -00 or -000, both seem to work.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-29 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found