[comp.unix.questions] AWK Language Question

boi@richsun.cpg.trs.reuter.com (Ken Boi) (08/11/90)

According to the book "The AWK Programming Language", there
are built-in string functions. One of them is 'gsub'. I have 
tried using it with the following comand line statement which
is very close to the example in the book:

		awk '{ gsub(/USA/, "United States"); print }' awkdata

where 'awkdata' is any text file. I get the error messages:

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

Anybody know why?

gwyn@smoke.BRL.MIL (Doug Gwyn) (08/13/90)

In article <972@richsun.cpg.trs.reuter.com> boi@richsun.cpg.trs.reuter.com (Ken Boi) writes:
>According to the book "The AWK Programming Language", there
>are built-in string functions. One of them is 'gsub'. I have 
>tried using it with the following comand line statement which
>is very close to the example in the book:
>		awk '{ gsub(/USA/, "United States"); print }' awkdata
>where 'awkdata' is any text file. I get the error messages:
>		awk: syntax error near line 1
>		awk: illegal statement near line 1
>Anybody know why?

Sure -- your version of "awk" is an old one that doesn't support that
feature.  Except for the first chapter or so of the AWK book, the examples
depend on having a more modern version of awk.  If you have a command "nawk"
try using that.  Otherwise, you can obtain the new flavor of awk from the
AT&T UNIX System ToolChest, or from UNIX System V Release 3.2 or later,
or a (supposedly) functionally equivalent utility called "gawk" from the
GNU project.

norm@oglvee.UUCP (Norman Joseph) (08/13/90)

In <972@richsun.cpg.trs.reuter.com>, boi@richsun.cpg.trs.reuter.com
(Ken Boi) writes:

>According to the book "The AWK Programming Language", there
>are built-in string functions. One of them is 'gsub'. I have 
>tried using it with the following comand line statement which
>is very close to the example in the book:
> [...]
>I get the error messages:

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

>Anybody know why?

The awk you are running on your system (you don't tell us what you have)
is an earlier version of the one described in _The_AWK_Programming_Language_,
which is a (relatively) recent update.  If your system is like some, you
may have the new version of awk listed under the name "nawk" (new awk).
-- 
Norm Joseph                                      cgh!amanue!oglvee!norm@dsi.com
  Oglevee Computer Systems, Inc.                {pitt,cgh}!amanue!oglvee!norm
      "Shucking Usenet oysters in pursuit of a pearl."  --  Bill Kennedy

guy@auspex.auspex.com (Guy Harris) (08/15/90)

>Otherwise, you can obtain the new flavor of awk from the AT&T UNIX
>System ToolChest, or from UNIX System V Release 3.2 or later,

It first appeared in S5R3.1.