I've been asked to post a summary of my nawk troubles. The problem
was:
>setting variables on the command line, as in:
>
> nawk '
> ....
> ' var="foo"
>
>Apparently, var no longer takes effect in BEGIN, but only in the
>main body. To get the old functionality:
>
> nawk '
> ....
> ' -v var ="foo"
>
>is supposed to work (and indeed, -v is listed as one of the options)
>when the usage is displayed, but when i try to use it, i get:
> nawk: can't open file -v
This is what I learned:
There are THREE (not two) versions of awk, they are:
awk or oawk, depending on your vendor,
nawk for sys5.r3
nawk for sys5.r4
R4 differs from R3 in that it tries to follow the specs on
assigning variables outside the awk program. That is why I
was having my intial problem, being suddenly confronted with
a "fixed" program :-)
nawks usage statement is:
Usage: nawk [-f programfile | 'program'] [-Ffieldsep] [-v var=value] [files]
^^^^^^^^^ ^^^^^^^^^^^^
which would indicate that the offered solution would work, but it
doesn't (at least not here). The correct format is:
nawk -v var="foo" 'program' [files]
Had I read the manpage (or used common sense) this would have
been obvious. The downside to all of this, is that R3 and R4
and quite incompatible on this subject. R3 requires the
var="foo" to be AFTER the program, while R4 requires it (and the -v)
to be BEFORE the program. Oh well, so it goes.
-- Richard Mitchell | mitchell@aol12.wff.nasa.gov | N3LNK |
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:08:17 CDT