#!/pkg/gnu/bin/perl ## CHANGE THIS FOR YOUR SYSTEM # # Name: cleanshar.pl # Purpose: Clean up shar files where 'END_OF_FILE' doesn't appear at # the beginning of a line. # Usage: cleanshar.pl sharFile ... # Method: If the shar file is not ok, a copy of the file is made in # sharFile.bad and the good copy replaces the bad one. A # summary message is sent to STDOUT # Revisions: # 3/7/2000: Bug Fix: Changed use of 'break' to 'last'. # $EOF = 'END_OF_FILE'; foreach $i (0 .. $#ARGV) { # go thru arguments one at a time $fname = $ARGV[$i]; open(SHARFILE, "<$fname") || die "Can't open the file $fname"; $ok = 1; while () { if (/^(X.*)$EOF$/) { # found bad line $ok = 0; last; } } close($SHARFILE); if ($ok == 0) { system "cp", "$fname", "$fname.bad"; open(BADSHARFILE, "<$fname.bad") || die "Can't open the bad file $fname.bad"; unlink "$fname"; open(SHARFILE, ">$fname") || die "Can't open the bad file $fname"; while () { if (/^(X.*)$EOF$/) { # bad line print SHARFILE $1, "\n"; # output line without EOF print SHARFILE $EOF, "\n"; # now the EOF on its own line } else { # good line print SHARFILE $_; # output line } } close(SHARFILE); close(BADSHARFILE); print "$fname has been updated; $fname.bad is the original file\n"; } else { print "$fname is clean\n"; } }