open (IFILE,$pfile)||&log_it("Unable To Open Input File $pfile $!"); while (my $line=) { $cnt = $cnt+1; if (substr($line,0,7) eq "1SYSTEM") { $header=1; } if ($header <=8) { #skip the 8 lines of the header $header = $header +1; } else { if ($line=~/\x00/||$line=~/\x1A/||$line=~/\x2A/) { #skip the lines that have the hex value of 00, 1A #and skip the summary lines - marked with a * $x=x; } #these lines will have usable data else { #take the first chunck of the line, which is the SIC, username and ID #break it up into its components by making it pipe | delimited $sub_line=substr($line,0,38); $sub_line=~s/\s+\s+/\|/g; #get the positions of the pipes $a=index($sub_line,'|',1); $b=index($sub_line,'|',8); $c=index($sub_line,'|',20); #assign the values my $index=substr($sub_line,0,$a); my $username=substr($sub_line,$a+1,$b-($a+1)); my $id=substr($sub_line,$b+1,$c-($b+1)); my $new_index; #get rid of leading 0 in index value $index=~s/^0//; #print "start '$index' ($prev_user,$username): "; # if the index code is 0 or blank, then use # the last known SIC value, padded to 7 characters if ($index eq '' ) { $index=sprintf("%-*s",7,$prev_index); #print "Null Index -> $index\n"; } else { $index=sprintf("%-*s",7,$index); } # if the username is blank then use the last # known username value and pad it to 22 characters # and use the last known user ID padded to 8 characters if (trim($username) eq '') { $username=sprintf("%-*s",22,$prev_user); if ($id eq "") { $id=sprintf("%-*s",8,$prev_id); } else { $id=sprintf("%-*s",8,$prev_id); } # remove the initial white space from the "blank" lines # then reconstruct the output line $line=ltrim($line); $line=~s/^0//; $prev_user=$username; $prev_index=$prev_index; $prev_id=$id; print OFILE $period." ".$index.$username.$id.$line } #if the index and username were filled in, the assign these values #to the previous variables and print the record else { $line=~s/^0//; $prev_user=$username; $prev_index=$index; #$prev_index=~s/^0//; $prev_id=$id; print OFILE $period." ".$line } } } } #end while loop