which awk program is causing the error? 
Author Message
 which awk program is causing the error?



Quote:
> Hello,

> consider the following pipeline:

> awk ' ... '  | awk ' ... ' | awk ' ... '

> If one of the awk program generates an error, one get's the
> linenumber, but not which awk program caused the error.

I'm not sure if you're using UNIX, DOS or something else.  If UNIX,
I've often used the following method during debugging of a pipeline.
I'll use the awk example you've given above, but the technique works
for ANY sequence of programs in a pipe.

If you have some code like this (in a UNIX shell script):

   awk '...' |
   awk '...' |
   awk '...'

you can insert a line:

   cat;exit

between lines.  This will dump the output and stop the script at
that point.  This is useful for:

(a) Locating errors - you start with the "cat;exit" line early in
    the script, iron out errors up to that point, and then gradually
    move it down the script;

(b) Checking intermediate output in the pipeline.

So in your case, put this line after the first awk and run the script.
If you get an awk error, it's in the first awk.  Then move the "cat;exit"
down one line, and try again.  And so on.

This is great when you're trying to debug a shell script (whether
or not it contain awk's).  If this applies to you, I hope this has
been of help.

Quote:
> Francky

Gihan

-----------------------------------+----------------------------------------
| Gihan Perera                     |  Me--> * U.K.                         |
|                                  |                                       |

|                                  |                            /     \    |
|                                  |                    Home--> *_,-._/    |
|                                  |                                 v     |
-----------------------------------+----------------------------------------



Mon, 10 Aug 1998 03:00:00 GMT  
 which awk program is causing the error?
Hello,

consider the following pipeline:

awk ' ... '  | awk ' ... ' | awk ' ... '

If one of the awk program generates an error, one get's the
linenumber, but not which awk program caused the error.

Is there a way to give each of the awk programs an identification?
I tried with setting ARGV[0], which didn't give the disired result.

Francky

--
-----------------------------------------------------------------------------
 Francky Leyn

 Kardinaal Mercierlaan 94 - 91.21   Tel    : ++32 - (0)16  32.10.85
 B-3001 Heverlee - Belgium          Fax    : ++32 - (0)16  32.19.75
-----------------------------------------------------------------------------



Mon, 10 Aug 1998 03:00:00 GMT  
 which awk program is causing the error?
: Hello,

: consider the following pipeline:
: awk ' ... '  | awk ' ... ' | awk ' ... '
: If one of the awk program generates an error, one get's the
: linenumber, but not which awk program caused the error.
: Is there a way to give each of the awk programs an identification?
: I tried with setting ARGV[0], which didn't give the disired result.

Gotta admit, this is my first awk program, just written 5 minutes
ago, just for you. (Ok, I'm a professional C/C++ programmer)

Have fun,

Jelle

---- program start ----

# this program will keep track of how many times it has been run

BEGIN {
    getline < "debug.tmp"
    close("debug.tmp")          # to be able to rewrite the file
    $passnr=$2 + 1
    print "pass ", $passnr > "debug.tmp"
    close("debug.tmp")          # just for safety

Quote:
}

# now do something usefull, print each line of input for example....

{ print }

---- program end ----

--
+-------------------------------------------------------+

| Vrije Universiteit Amsterdam    |                     |
+-------------------------------------------------------+



Mon, 10 Aug 1998 03:00:00 GMT  
 which awk program is causing the error?

: : Hello,

: : consider the following pipeline:
: : awk ' ... '  | awk ' ... ' | awk ' ... '
: : If one of the awk program generates an error, one get's the
: : linenumber, but not which awk program caused the error.
: : Is there a way to give each of the awk programs an identification?
: : I tried with setting ARGV[0], which didn't give the disired result.

[ not working program deleted ]

it seemed that the unix awk works differently than the dos awk I
tried this on. Now I tested under nawk, and the following works finde.
Sorry I have no "true awk" example.

# this program will keep track of how many times it has been run

BEGIN {
    getline < "debug.tmp"
    close("debug.tmp")
    passnr=0
    if (NF>1)
        passnr=$2 + 1
    print "pass ", passnr > "debug.tmp"
    close("debug.tmp")          # just for safety

Quote:
}

# now do something usefull, print each line of input for example....

{ print }

--
+-------------------------------------------------------+

| Vrije Universiteit Amsterdam    |                     |
+-------------------------------------------------------+



Mon, 10 Aug 1998 03:00:00 GMT  
 which awk program is causing the error?
[if you have a pipeline like]
Quote:
>: : awk ' ... '  | awk ' ... ' | awk ' ... '

[and one of the programs crashes; how can you tell which one it was?]

Quote:

># this program will keep track of how many times it has been run

:BEGIN {
:    getline < "debug.tmp"
:    close("debug.tmp")
:    passnr=0
:    if (NF>1)
:        passnr=$2 + 1
:    print "pass ", passnr > "debug.tmp"
:    close("debug.tmp")          # just for safety
:}

:# now do something usefull, print each line of input for example....

:{ print }

Unfortunately, that doesn't help.
(1) Have you read the fine print in your shell manual lately so that
    you know what order the commands in a pipe are started?

        awk '...prog1...' | awk '...prog2...' | awk '...prog3...'

    may well start the LAST command in the pipeline first.

(2) Regardless of what the commands in the pipeline are STARTED first,
    they notionally RUN in parallel.  That is, after all, the point of
    a pipeline.

ONLY if you are using a shell-look-alike where commands in a pipeline
are guaranteed to be executed to completion in strict left to right order
(i.e. not any known UNIX shell) can you rely on this technique to work.

Even in that circumstance, you still have to worry about creating the
file in the first place, or you know that all the awk programs will die
in the line where they try to open the file...

If only one of the commands fails, something like
        (awk '...prog1...' || echo ONE failed 1>&2) | \
        (awk '...prog2...' || echo TWO failed 1>&2) | \
        (awk '...prog3...' || echo THREE failed 1>&2)

But the simplest thing by far that I can think of is to put the awk
programs in files.  When the awk run-time reports an error, it cites
the source file name.  So just use
        awk -f prog1.awk | awk -f prog2.awk | awk -f prog3.awk
and the identification problem should be solved.

I _always_ put the awk script in a file, because I often have to fiddle
with it to get the regular expressions right.

--
Election time; but how to get Labor _out_ without letting Liberal _in_?
Richard A. O'Keefe; http://www.cs.rmit.edu.au/~ok; RMIT Comp.Sci.



Fri, 14 Aug 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. An Awk Program to Create an Awk Program [Long]

2. Fortran program causing a Windows thread space error R6016

3. AWK newbie is looking for a AWK help with his 1st program

4. What Causes Error 48-Unable To Log Transaction

5. Maximizing window cause error

6. C55srvx causes an error in C55llpex.dll

7. Report Writer with many pass parameters causes error on Win Millennium

8. What is causing this error message???

9. Making @appname.lnk causes illlegal operation error

10. API CreateFileA causes ERROR_INVALID_PARAMETER error opening port

11. Put in Process Causes Error

 

 
Powered by phpBB® Forum Software