[comp.unix.shell] Exporting Awk Variables?

gcs@polari.UUCP (Greg Sheppard) (05/27/91)

 This is probably a repeat question but the thread scrolled by (at
least I think I remember something along the same lines awhile back).
Is it possible to export a variable within awk so the variable
could be used by a shell script?  I have an awk script which
increments a variable "i".  When awk is finished I'd like to pass
the value of "i" to the same shell script which calls awk.
 Email responses would be fine or if someone could point me to
a location where comp.unix.shell is archived...I can try to look
it up.  Thanks!
-- 
Greg Sheppard                        Internet:  imop@wa-ngnet.army.mil
WAARNG, Tacoma, WA, USA              UUCP:      ...!polari!gcs 
Voice: +1 206 581 8924
--

john@chinet.chi.il.us (John Mundt) (05/29/91)

In article <4255@polari.UUCP> gcs@polari.UUCP (Greg Sheppard) writes:
>
> This is probably a repeat question but the thread scrolled by (at
>least I think I remember something along the same lines awhile back).
>Is it possible to export a variable within awk so the variable
>could be used by a shell script?  I have an awk script which
>increments a variable "i".  When awk is finished I'd like to pass
>the value of "i" to the same shell script which calls awk.
> Email responses would be fine or if someone could point me to
>a location where comp.unix.shell is archived...I can try to look
>it up.  Thanks!

You can wrap the awk script in backslashes and have it write
the output of i as it exits to stdout and assign it to a variable
in the calling script, as in

....
RET_VAR=`awk ' { do_somthing; ...}; END { printf("%d",i); }'`
...

RET_VAR will hold the value of i.  You would proably have to
use awk's redirect functions to send other useful output to a
file.  Alternatively, you could use the END statement to print
the value to a temp file, and then read that number into 
RET_VAR.
-- 
---------------------
john@admctr.chi.il.us
John Mundt   Teachers' Aide, Inc.  P.O. Box 1666,  Highland Park, IL
(708) 998-5007 || -432-8860