#perl -w # preprocess-FixEmbeddedCRLFs.pl # Perl script to fix the embedded CR/LF's that are embedded in the ULS "text" files # n6lhv@arrl.net (Wayne Smith) # created: 26-December-2004 # updated: 27-December-2004 # Set up the environment use strict; # Initialize some variables my $ulsFile = ""; my $oneRecord = ""; my $thisLine = ""; my $firstLine = ""; my $secondLine = ""; my $firstRecordFlag = "Yes"; my $firstLineFlag = "Yes"; my @allLines = ""; my $maxLines = 0; my $oneLine = ""; # Fix a single text file sub main { # Open the text file open (ulsFile, "<" . $ARGV[0] . ".dat") or die "Cannot open file '" . $ARGV[0] . ".dat' for reading..."; open (ulsFileNew, ">" . $ARGV[0] . "-new" . ".dat") or die "Cannot open file '" . $ARGV[0] . "-new" . ".dat for writing..."; # Generate a WorkBook using the command-line parameter # writeAWorkBook ($ARGV[0]); print "Reading the original file...\n"; @allLines = ; $maxLines = @allLines; print "Writing a new file...\n"; # foreach $oneLine (@allLines) { # if (substr($oneLine,0,2) eq "CP") { # print ulsFileNew "$oneLine"; # } # skip incomplete lines # } my $lineCounter = 0; $firstRecordFlag = "Yes"; foreach $oneLine (@allLines) { chomp($oneLine); # if (substr($allLines[$lineCounter],0,2) ne "") { # print ulsFileNew "$oneLine"; # } # else { # $lineCounter++; # next; # } print ulsFileNew "$oneLine"; if ($firstRecordFlag eq "Yes") { $firstRecordFlag = "No"; } else { $firstRecordFlag = "Yes"; } if ($lineCounter+1 < $maxLines && (substr($allLines[$lineCounter+1],0,2) eq "CP" || substr($allLines[$lineCounter+1],0,2) eq "EN" || substr($allLines[$lineCounter+1],0,2) eq "LO")) { print ulsFileNew "\n"; $firstRecordFlag = "Yes"; } else { $firstRecordFlag = "No"; } # print $lineCounter . "\n"; $lineCounter++; } print ulsFileNew "\n"; # Close the text files close(ulsFileNew); close(ulsFile); } # Main main;