User Tools

Site Tools


build:odm-comb.pl
#!/usr/bin/perl -w
#*******************************************************************************
#                                                                              *
# Program to combine multiline output from odmget and other stanza data.       *
#                                                                              *
#*******************************************************************************

#*******************************************************************************
# Misc setup
#*******************************************************************************

use English;

use File::Basename;
$PROGRAM_NAME=basename($PROGRAM_NAME);

#*******************************************************************************
# Process command line options
#*******************************************************************************

#None

#*******************************************************************************
# Start of before file processing
#*******************************************************************************

$more_lines = 1;

$out_line="";  # Empty output line

$total_in_lines  = 0;  # Grand total      Number of lines in input
$total_out_lines = 0;  # Grand total      Number of lines in output

#*******************************************************************************
# End of before file processing
#*******************************************************************************

#*******************************************************************************
# Start of line by line processing
#*******************************************************************************
line: while ($more_lines == 1 && defined($line=<>))
  {

chomp($line);      # strip record separator
# printf STDERR "%s\n",$line; ######## Debug

############ Skip non-data lines
if ($line =~ /^\#/)                        { next line; }

#*******************************************************************************
# Process lines of interest
#*******************************************************************************
if ($line =~ /%[123]/)
  {
    printf STDERR "Caution, line contains %% \"%s\"\n", $line;
  }
if (! $line =~ /^$/)
  {
    $total_in_lines++;        # Count of lines input
    $line=~s/^\s+//;  # Eliminate leading blanks
    $line=~s/%/%3/g;  # Change all % to %3
    $line=~s/ /%1/g;  # Change all blanks to %1
    $line=~s/\t/%2/g; # Change all tabs to %2
    #$line=~s/\s+//g; # Eliminate all blanks
    $out_line.=$line." "; # Add input line to combined output with a space
    #printf STDERR "line=\"%s\"\n", $line; ######## Debug
    #printf STDERR "out_line=\"%s\"\n", $out_line; ######## Debug
  }
  else {
    if ( length($out_line) gt 0 )
      {
        printf "%s\n",$out_line;
        $out_line="";  # Blank for next pass
        $total_out_lines++;       # Count of lines output
      }
  }

#*******************************************************************************
# End of line by line processing
#*******************************************************************************
    # print STDERR "Bottom of loop\n"; ######## Debug
  }
# print STDERR "Exited loop\n"; ######## Debug

if ( length($out_line) gt 0 )
  {
    printf "%s\n",$out_line;
    $total_out_lines++;
      }

#*******************************************************************************
# Start of end of file processing
#*******************************************************************************

printf STDERR "\n";
printf STDERR "total lines  input=%d\n", $total_in_lines;
printf STDERR "total lines output=%d\n", $total_out_lines;
printf STDERR "\nCounts exclude commands and blank lines.\n";

#*******************************************************************************
# End of end of file processing
#*******************************************************************************
build/odm-comb.pl.txt · Last modified: 2007/06/13 17:27 by 206.197.251.70