#! /usr/common/bin/gawk -f # # usage: testdead.awk EIS.file > NEW.file # or : testdead.awk EIS.file > /dev/null # # - testdead.awk reports the following four problems: # 1: keyword "dead" and %A found, 3: excessively long lines, # 2: neither "dead" nor %A found, 4: long %N lines (> 500). # - testdead.awk modifies nothing, all input lines are copied, so # using this script in a pipe should work as expected. e.g. use # testsign.awk EIS.file | testdead.awk | testmore.awk > NEW.file # - all errors, changes, and unsolved problems reported in LOGFILE, # see below BEGIN (use e.g. file ./report_dead or /dev/tty etc.) # #### report error ################################################# function ERROR( TXT ) { TXT = "%A " TXT if ( DEAD ) TXT = TXT " found in dead sequence" else TXT = TXT " missing (not \"dead\")" print TXT " before line " NR > LOGFILE return 1 } #### length limit ################################################# function LIMIT( N ) { if ( length( $0 ) < N ) return 0 print $1, $2 " length " length( $0 ) " in line " NR > LOGFILE return 1 } #### LOGFILE ###################################################### BEGIN { LOGFILE = "report_dead" # keep error messages DEAD = 0 ; AUTH = 1 ; ID = "?" } #### note ID ###################################################### /^%I A/ { if ( DEAD == AUTH ) MM = MM + ERROR( ID ) DEAD = 0 ; AUTH = 0 ; ID = $2 } /^%K A.*dead/ { DEAD = 1 } # note keyword "dead" /^%A A/ { AUTH = 1 } # note found %A author #### check lengths ################################################ /^%N A/ { NN = NN + LIMIT( 500 ) # special limit for %N print ; next # copy all input lines } { NN = NN + LIMIT( 1000 ) # general length limit print ; next # copy all input lines } #### report number of found problems ############################## END { if ( DEAD == AUTH ) MM = MM + ERROR( ID ) print NN++ " very long lines" > LOGFILE print MM++ " dead %A errors" > LOGFILE if ( LOGFILE == "/dev/tty" ) exit print "see report in " LOGFILE ":" > "/dev/tty" print --NN " very long lines" > "/dev/tty" print --MM " dead %A errors" > "/dev/tty" }