From: Carlo Strozzi <carlos@linux.it> To: fosterd@hartwick.edu Cc: rc@hawkwind.utcs.toronto.edu Subject: Re: environment again Date: Thu, 8 Jun 2000 15:02:52 -0400 [thread overview] Message-ID: <E1307Zs-0001R0-00@localhost> (raw) 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
next reply other threads:[~2000-06-09 8:35 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2000-06-08 19:02 Carlo Strozzi [this message] 2000-06-12 15:23 ` Tim Goodwin 2000-06-12 16:35 ` Carlo Strozzi -- strict thread matches above, loose matches on Subject: below -- 2000-06-08 7:19 Carlo Strozzi 2000-06-08 16:48 ` Decklin Foster 2000-06-07 6:53 Carlo Strozzi 2000-06-08 5:55 ` Decklin Foster
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=E1307Zs-0001R0-00@localhost \ --to=carlos@linux.it \ --cc=carlos@texne.com \ --cc=fosterd@hartwick.edu \ --cc=rc@hawkwind.utcs.toronto.edu \ --subject='Re: environment again' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).