#!/usr/local/bin/perl -s # # condense.pl # # Remove redundant empty lines # Run condense.pl -h to see the options # # Last modified: 8/7/96 # Author: Bekman Stas # $0 =~ s/^.*\///; # cut the basename of the command # Diagnostic part... if ($#ARGV<0 || $h) { die "\n\tRemoves redundant empty lines Usage: \t $0 file(s) options: -h you read me now -no_bak Don't backup the original file -none Don't leave one empty line between paragraphs \n" } # Real program... # Store the original files' modes (Must do! Because of open(Bla,">foo") ) foreach (@ARGV) { $modes{$_}=(stat)[2]; } while (<>){ if ($ARGV ne $oldargv){ if (!$no_bak) {rename($ARGV, $ARGV . '.bak');} open (ARGVOUT, ">$ARGV") || die("Can't open $ARGV[0]: $!\n"); select(ARGVOUT); $oldargv= $ARGV; } if ($empty) {s/^\s*\n//; (!$none) && ($empty=0);} if (/^\s*$/) {$empty=1;} } continue { print; # this prints to the original filename } close(ARGVOUT); select(STDOUT); # Restore the original files' modes (Must do! Because of open(Bla,">foo") ) foreach (keys %modes) { chmod $modes{$_},$_; }