#! /bin/gawk -f # # usage: nomore.sh cat25 > NEW.file # or : nomore.sh cat25 > /dev/null # # Date: Sun, 03 Feb 2002 07:16:23 +0100 # Written by Frank Ellermann # # The name of this file is nomore.sh (not nomore.txt) # # The very first line may need to be changed to point to your # local version of gawk! # Please replace three "/dev/con" by "/dev/tty" resp. "/dev/stderr" # if necessary, use e.g. "nomorexu" as name, and chmod +x nomorexu #### report error on /dev/tty ################################# function ERROR( BAD ) { print "ignored error near: " substr( BAD, 1, 58 ) > "/dev/tty" return "" # caller resets bad ID } #### count patches ################################################ BEGIN { NN = 0 } #### note ID ###################################################### /^%I A/ { ID = $2 ; U = "" ; X = "" print ; next # copy anything else } #### unknown ###################################################### ID == "" { print ; next # copy anything else } #### note %U ###################################################### /^%U A/ { if ( $4 == "" && $2 == ID && U == "" ) U = $3 else ID = ERROR( $0 ) # blank in terms etc. print ; next # copy anything else } #### note %X ###################################################### /^%X A/ { if ( $4 == "" && $2 == ID && X == "" ) X = $3 else ID = ERROR( $0 ) # blank in terms etc. print ; next # copy anything else } #### test %K ###################################################### /^%K A/ { if ( $4 == "" && $2 == ID ) { if ( X != "" ) U = X X = index( $3, "more" ) } else ID = ERROR( $0 ) # report unexpected ID if ( ID == "" || U == "" || X == 0 ) { ID = "" ; print ; next } X = match( U, /,[0-9]+$/ ) ; ID = "" if ( X == 0 ) # duplicate last term X = length( U "," U ) else X = length( U substr( U, X )) if ( X > 74 ) # no "more" terms fit: { gsub( /more,/, "" ) # remove _all_ "more" sub( /,more/, "" ) ; NN++ print "patching " $2 ": " X > "/dev/tty" } print ; next # copy (patched) keys } #### otherwise #################################################### { print ; next # copy anything else } #### report number of patched sequences on /dev/tty (?) ########### END { print NN " sequences patched" > "/dev/tty" }