awk arguments
Roger Rohrbach
roger at yuba.wrs.com
Wed Jul 25 06:21:06 AEST 1990
mayne at VSSERV.SCRI.FSU.EDU (William (Bill) Mayne) writes:
> I have never been able to get the command line assignment of
> awk variables to work.
I tried this on SunOS, too. It seems like a bug.
> The practical problem this raises is how to communicate an
> argument value or a value calculated by a script file into
> an awk program embedded in a script file.
This is simply a matter of escaping from the quoted awk program
to collect the values of shell variables. It can be done anywhere in
your awk program, but I tend to assign them all in the BEGIN section:
awk '
BEGIN {
user = "'$USER'";
arg = "'$1'";
}
{
print user, arg
}'
will set the awk variables user and arg to the values of the shell
variables $USER and $1, respectively, and then print them for each
awk input record.
> the version actually available on every flavor of unix
> I have seen is much weaker than the full version described by the book.
Yes, the awk supplied with most Unix systems dates from UNIX Version 7.
The book describes a version you must buy from the AT&T Toolchest! At
least, you had to do so when the book first came out; now you can get an
implementation of that language free- GNU awk (gawk). It chokes on my
best work (written in "old awk"), however, so I don't bother with it.
I am an old awk hand, and prefer the older ("weaker"?) version. The
addition of functions and all manner of bells and whistles to my beloved
pattern-directed little language disappointed me. To see how "weak" the
original awk is, see my recent posting of a complete LISP interpreter,
written in that version of awk, to comp.lang.lisp.
Roger Rohrbach sun!wrs!roger roger at wrs.com
- Eddie sez: ----------------------------------------------- (c) 1986, 1990 -.
| {o >o |
| \ -) "I was an infinitely hot and dense dot." |
More information about the Comp.unix.wizards
mailing list