From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.libero.it ([193.70.192.51]) by hawkwind.utcs.toronto.edu with SMTP id <28679>; Fri, 9 Jun 2000 04:35:21 -0400 Received: from LocalHost (151.15.133.179) by smtp1.libero.it; 8 Jun 2000 21:38:54 +0200 Received: from carlos by localhost with local (Exim 2.05 #1 (Debian)) id 1307Zs-0001R0-00; Thu, 8 Jun 2000 21:02:52 +0200 To: fosterd@hartwick.edu Subject: Re: environment again Cc: rc@hawkwind.utcs.toronto.edu Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 X-Mailer: mailx v8.1.1 ;-) Reply-To: carlos@texne.com Organization: TeXne.COM Message-Id: From: Carlo Strozzi Date: Thu, 8 Jun 2000 15:02:52 -0400 Decklin Foster wrote: | Carlo Strozzi writes: | | > sed 's/__SPECIAL_TAG__/'^$my_big_var'/' page_template.html | | OK, but where is $my_big_var set? That's what I need to know to figure | out how to write it without the variable. Hmm .. ok, I'll try and provide a reasonably simple example. I often use flat-file ascii tables with the following sample structure: ; cat mytable Col1 Col2 Col3 ---- ---- ---- data1 data2 some-big-data where the data parts may contain stuff that "bytes", especially if exposed to an 'eval' statement. Then suppose I need to use data1 and data2 in several places in my shell script, and some-big-data needs to be passed to sed(1) for substitution on the output page template (as per my previous message). Furthermore, all this needs to be done with the least possible No. of processes, as we are talking about high traffic web sites. All the above can actually be done in one single call to awk, like this: eval `{awk 'awk program' mytable} where 'awk program' is supposed to: 1) escape sed(1) special chars in some-big-data 2) further escape shell special chars in all the data parts 3) return the following fragment of rc code: { Col1='data1'; Col2='data2'; Col3='some-big-data' } This makes it possible to eval awk's output and grab the results back into the calling shell script for later use, for instance in the aforementioned statement: sed 's/__SPECIAL_TAG__/'^$Col3'/' page_template.html Of course one way out could be to have 'awk program' only return { Col1='data1'; Col2='data2' } while writing the sed(1) statement 's/__SPECIAL_TAG__/some-big-data/' to a temporary file, to be later used as: sed -f tmpfile page_template.html This would cost us: - one more i/o from awk to write tmpfile - one more i/o for sed to read tmpfile - one more rm(1) process to remove tmpfile on exit which multiplied by the two-million times our CGI gets hit every day ... :-) Furthermore, 'awk program' would be less general as it would need to treat some-big-data differently from data1/data2. | > you will need a system(3), | | Feh. fork/exec. But that's totally off-topic, so nevermind. Oh, I wasn't talking about C, but rather PHP or other mainstream interpreted languages for CGI scripting, or even awk, that whatever external program it needs to run it calls it with '/bin/sh -c'. This is true at least with mawk/gawk. bye --carlo