[comp.unix.wizards] awk problem

reo@cbnews.cb.att.com (robert.e.o'brien) (04/23/91)

This is embarrassingly simple, but I can't figure it out.  The awk book 
by the Aho, Kernigan, and Weinberger have info about piping in input
using the getline function.

When I try (see p. 62 of book which has "date" | getline d):

{ "date" | getline d 
print d }

I get:

awk: syntax error near line 1
awk: illegal statement near line 1

I've tried a number of variations on this.  What am I doing wrong?
Thanks in advance.

Bob O'Brien

urban@cbnewsl.att.com (john.urban) (04/23/91)

In article <1991Apr23.104858.26935@cbnews.cb.att.com> reo@cbnews.cb.att.com (robert.e.o'brien) writes:
>This is embarrassingly simple, but I can't figure it out.  The awk book 
>by the Aho, Kernigan, and Weinberger have info about piping in input
>using the getline function.
>
>When I try (see p. 62 of book which has "date" | getline d):
>
>{ "date" | getline d 
>print d }
>
>I get:
>
>awk: syntax error near line 1
>awk: illegal statement near line 1
>
>I've tried a number of variations on this.  What am I doing wrong?
>Thanks in advance.
>

Under UNIX System V/386 Release 3.2 (and Release 4.0) there are two versions of
awk.  Plain old awk and nawk.  Nawk is new awk.  nawk supports alot of things
that awk does not (e.g. system("cmd") and your example above.

Type in:

$ type nawk

If you got nawk, then your run program on that.  On my machine, your program
ran fine with nawk and died with awk.

Sincerely,

John Urban

reo@cbnews.cb.att.com (robert.e.o'brien) (04/24/91)

nawk did the trick.  Thanks John and others who pointed this o
ut.

Bob

From article <1991Apr23.143542.28233@cbnewsl.att.com>, by urban@cbnewsl.att.com (john.urban):
> In article <1991Apr23.104858.26935@cbnews.cb.att.com> reo@cbnews.cb.att.com (robert.e.o'brien) writes:
>>This is embarrassingly simple, but I can't figure it out.  The awk book 
>>by the Aho, Kernigan, and Weinberger have info about piping in input
>>using the getline function.
>>
>>When I try (see p. 62 of book which has "date" | getline d):
>>
>>{ "date" | getline d 
>>print d }
>>
>>I get:
>>
>>awk: syntax error near line 1
>>awk: illegal statement near line 1
>>
>>I've tried a number of variations on this.  What am I doing wrong?
>>Thanks in advance.
>>
> 
> Under UNIX System V/386 Release 3.2 (and Release 4.0) there are two versions of
> awk.  Plain old awk and nawk.  Nawk is new awk.  nawk supports alot of things
> that awk does not (e.g. system("cmd") and your example above.
> 
> Type in:
> 
> $ type nawk
> 
> If you got nawk, then your run program on that.  On my machine, your program
> ran fine with nawk and died with awk.
> 
> Sincerely,
> 
> John Urban