Debugging Awk scripts

Chris Hare / System Manager chris at choreo.COM.COM
Wed Mar 21 06:04:35 AEST 1990


Hello World.  (Little joke)

I am in need of some help in debugging an awk script.  The script works on
SCO XENIX 2.3.2, but doesn't work on Motorola UNIX, which is an SVR3
implementation.

I ahve included the awk script below.  What I need to know is when awk
reports a line number, how and when does it start counting lines.

The message I get back is syntax error at or near line 141.  I have marked
in the script where I *think* line 141 is.

Any suggestions would be appreciated.

------------------------------------------------------------
Chris Hare, Co-ordinator, Systems Management         *** IT WORKS FOR ME! ***
Authorized SCO Instructor
Choreo Systems Inc.                                  500-150 Laurier Ave W.
                                                     Ottawa, Ontario K1P 5J4
E-MAIL ...!choreo!chris                              Voice (613) 238-1050
                                                     Fax   (613) 238-4453


awk 'BEGIN {
    print "This is the start"
    }
    {
   if ( PRINTED == 0 && DONE != "YES" )
      {
      printf "START   START   FINISH   FINISH   CONNECT   FILES  STATUS\n"
      printf "DATE    TIME     DATE     TIME     TIME     XFERD\n" 
      DONE="YES"
      }

   USER=$1
   DATE=$2
   HRS=$3
   MINS=$4
   SECS=$5
   PID=$6
   FILES=$7
   CMD=$8
   CMD2=$9
   CMD3=$10
   CMD4=$11
   STATUS=""

   if ( CMD == "CAN" && CMD2 == "NOT" )
      {
      START_DATE=DATE
      START_HRS=HRS
      START_MINS=MINS
      START_SECS=SECS
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      STATUS="Status - No Call"
      PRINT="YES"
      CALCULATE="YES" 
      }

   if ( CMD == "NO" && CMD2 == "CALL" )
      {
      START_DATE=DATE
      START_HRS=HRS
      START_MINS=MINS
      START_SECS=SECS
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      STATUS="Retry Time has not been Reached"
      PRINT="YES"
      CALCULATE="YES" 
      }

   if ( CMD == "FAILED" && CMD2 == "LOGIN" )
      {
      START_DATE=DATE
      START_HRS=HRS
      START_MINS=MINS
      START_SECS=SECS
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      STATUS="Login Failed"
      PRINT="YES"
      CALCULATE="YES" 
      }

   if ( CMD == "CONN" && CMD2 == "FAILED" && CMD3 == "WRONG" )
      {
      START_DATE=DATE
      START_HRS=HRS
      START_MINS=MINS
      START_SECS=SECS
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      STATUS="Request(s) Queued"
      PRINT="YES"
      CALCULATE="YES" 
      }

   if ( CMD == "CONN" && CMD2 == "FAILED" && CMD3 == "CALLER" )
      {
      START_DATE=DATE
      START_HRS=HRS
      START_MINS=MINS
      START_SECS=SECS
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      STATUS="No Connection Made"
      PRINT="YES"
      CALCULATE="YES" 
      }

   if ( CMD == "SUCCEEDED" )
      {
      START_DATE=DATE
      START_HRS=HRS
      START_MINS=MINS
      START_SECS=SECS
      CONNECTION="YES"
      }

   if ( CMD == "FAILED" && CMD2 == "conversation" && CONNECTION == "YES" )
      {
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      PRINT="YES"
      STATUS="Connection Made - Transfer Failed"
      CONNECTION="NO"
      CALCULATE="YES" 
      }

   if ( CMD == "OK" && CMD2 == "conversation" && CONNECTION == "YES" )
      {
      END_DAY=DATE
      END_HRS=HRS
      END_MINS=MINS
      END_SECS=SECS
      PRINT="YES"
      STATUS="Success"
      CONNECTION="NO"
      CALCULATE="YES" 
      }

   if ( CALCULATE == "YES" )
      {
      CON_SECS=END_SECS-START_SECS
      if ( CON_SECS < 0 )
	 CON_SECS=CON_SECS * -1
      CON_MINS=END_MINS-START_MINS
      if ( CON_MINS < 0 )
	 CON_MINS=CON_MINS * -1
*** 141 ??? ***      CON_HRS=END_HRS-START_HRS
      if ( CON_HRS < 0 )
	 CON_HRS=CON_HRS * -1
      CALCULATE="NO" 
      }

   if ( PRINT == "YES" )
      {
      printf "%5s %02d:%02d:%02d ",START_DATE,START_HRS, START_MINS, START_SECS
      printf "%5s %02d:%02d:%02d ", END_DAY, END_HRS, END_MINS, END_SECS
      printf "%02d:%02d:%02d ", CON_HRS, CON_MINS, CON_SECS
      printf "%5d %s %s\n", FILES, CONNECT, STATUS 
      PRINT="NO"
      PRINTED=PRINTED + 1

      if ( PRINTED == 50 )
	 {
	 PRINTED=0
	 printf "\f"
	 DONE="NO"
	 }
      }
   }'



More information about the Comp.unix.questions mailing list