[lug] Those Pesky Newlines
    Joseph P. Crotty 
    jcrotty18 at attbi.com
       
    Fri Dec 27 00:50:00 MST 2002
    
    
  
> I'm partial to sed for this purpose, but if someone can do it in a Perl*
> one-liner I'd be just as grateful.
someone probably can, just not me! ;-)  As a script I used the following to solve the problem:
#!/usr/bin/perl
while (<>) {
	push(@file, $_);
}
for ($i = 0; $i < scalar(@file); $i++) {
	if (($file[$i] !~ /^\n$/) && ($file[$i + 1] !~ /^\n$/)) {
		$file[$i] =~ s/\n/ /;
	}
}
foreach (@file) {
	print $_;
}
just pass the script the name of the file on the command line.
    
    
More information about the LUG
mailing list