Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!mips!news.cs.indiana.edu!ux1.cso.uiuc.edu!midway!clout!chinet!john From: john@chinet.chi.il.us (John Mundt) Newsgroups: comp.unix.shell Subject: Re: Exporting Awk Variables? Keywords: awk export variables Message-ID: <1991May29.163856.7087@chinet.chi.il.us> Date: 29 May 91 16:38:56 GMT References: <4255@polari.UUCP> Organization: Chinet - Chicago Public Access UNIX Lines: 30 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