#! /usr/local/bin/perl $RCS_ID = '$Id: headchg,v 1.1 2006/09/08 19:05:53 hiram Exp $' ; $0 =~ s-.*/-- ; $HelpInfo = <){ print ; unless( /^#\s|^\s+#/ ){ last if ++$lln >= 2 ; } } } else{ &do_head ; } } if( ! $GEN ){ # copy body $lln = 0 ; while(){ if( $lln < 2 ){ unless( /^#\s|^\s+#/ ){ $lln++ ; } next unless $ADD ; } print ; } } if( ! $DEL && ! $COPY && ! $QUIET ){ $x = scalar(@s) ; printf STDERR "Columns: %d\n", $x ; } sub do_head { # gen, write new header while(){ next if /^\s*$/ ; # skip blank lines if( /^\s*#/ ){ # comment line if( ! $lln && $COMM ){ if( /^#\S/ ){ s/^#/# / ; }# chg to valid format print ; } next ; } $lln++ ; # logical line nr chop ; if( $lln <= 2 && $rdb ){ next ; } if( $lln == 1 && /^\s*[01]\.?\s/ ){ $mode2++ ; } @a = () ; while( s/\s*(\S+)// ){ # parse the line $x = $1 ; if( $x =~ /^\"/ ){ # dbl quote ... $x =~ s/^\"// ; if( $x !~ /\"$/ ){ s/[^"]*\"// ; $x .= $& ; } $x =~ s/\"$// ; } push( @a, $x ) ; } shift( @a ) if $mode2 ; # rm index nr, if any print "\t" if $needtab++ > 0 ; print shift @a ; # print col name $x = join( ' ', @a ) ; $x =~ s/ +.*$// if ! $COMM ; push( @s, $x ); } print "\n" ; print join( "\t", @s ), "\n" ; # print data definitions }