On Jan 20, 2004, at 12:39 PM, Lewick, Taylor wrote:

Hi all, I could use some help with an expression or code to delete
multiple blank lines and replace it with only one blank line...

I know how this can be done in sed, but am not sure how to do it in
perl...

Well, if slurping is okay (read: file size is reasonable), I would probably use something like this (untested code):


#!/usr/bin/perl

use strict;
use warnings;

die "Usage: perl script_name OLD_FILE NEW_FILE\n" unless @ARGV == 2;

open OLD, '<', shift() or die "File error:  $!\n";
my $text = join '', <OLD>;
close OLD;

$text =~ s/\n(?:\s*\n)+/\n/g;

open NEW, '<', shift() or die "File error:  $!\n";
print NEW $text;
close NEW;

__END__

Hope that helps.

James


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to