
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.