Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Double blank lines to single blank line

by shigetsu (Hermit)
on May 10, 2007 at 23:45 UTC ( [id://614780]=note: print w/replies, xml ) Need Help??


in reply to Double blank lines to single blank line

Dangerous (be sure to have an independent backup before you read on):

If you want to edit the data in place, you could use

perl -ibak -we 'local $/ = "\n\n"; while (<>) { local $/ = "\n"; chomp +; print }' ./data.dat

Be aware that it'll apply the changes immediately, but will create a backup of the file edited with the extension .bak. Furthermore, this approach assumes that your _entire_ input file looks like the excerpt you provided. Bear in mind that otherwise perhaps, chaos will ensue.

Replies are listed 'Best First'.
Re^2: Double blank lines to single blank line
by Util (Priest) on May 11, 2007 at 01:12 UTC
    Yet another quick method, via "paragraph mode":
    perl -00 -wpe 1 data.dat >data_singled.dat
    See perlrun for the meanings of the flags.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-16 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found