Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Removing double carriage return

by Cristoforo (Deacon)
on Aug 20, 2011 at 02:03 UTC ( #921353=note: print w/ replies, xml ) Need Help??


in reply to Removing double carriage return

Use the file slurp argument switch, '0'

perl -i.bak -0pe 's/\n\n/\n/g' inputtext

Update: I chose zero instead of octal 0777 thinking it would be clearer but GrandFather may have a good point, (a byte having possible values of 0 to 255 and the base 10 value of 0777 is 511). I guess I was thinking also that double zero, 00, is the switch for paragraph mode reading.


Comment on Re: Removing double carriage return
Download Code
Re^2: Removing double carriage return
by GrandFather (Cardinal) on Aug 20, 2011 at 02:54 UTC

    actually:

    perl -i.bak -0777pe 's/\n\n/\n/g' inputtext

    may be sightly better as no byte value matches octal 777, although that's rather nit picking and I'd have not noticed if I hadn't have needed to look up perlrun to find out what -0 (the digit 0 btw) actually does. ;)

    True laziness is hard work

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-12-25 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (162 votes), past polls