Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: Novice Question, Successive Lines Keywords: Novice Question, Successive Lines Message-ID: <100742@convex.convex.com> Date: 21 Mar 90 14:32:26 GMT References: <13447@cgl.ucsf.EDU> Sender: usenet@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: na Organization: CONVEX Software Development, Richardson, TX Lines: 29 In article <13447@cgl.ucsf.EDU> alonso@maxwell.mmwb.ucsf.edu (Darwin Alonso) writes: >How would one get perl to replace two or more successive blank lines >with one blank line? You can do this: #!/usr/bin/perl -n next if /^$/ && $skip++; print; $skip &= /^$/; Or as a one liner: perl -n -e 'next if /^$/ && $skip++; print; $skip &= /^$/;' Or you if you have lots of memory or little files: undef $/; $_ = <>; s/\n{3,}/\n\n/g; print; --tom -- Tom Christiansen {uunet,uiucdcs,sun}!convex!tchrist Convex Computer Corporation tchrist@convex.COM "EMACS belongs in : Editor too big!"