On 14 Mrz., 08:49, "tbh" <fem...@[EMAIL PROTECTED]
> wrote:
> thanks, Ed,
>
> > Someone had suggested you do something like this:
>
> > base=3D"f30"
> > unpackHourlyWebLogs.bash =A011 | gawk 'tolower($5) ~ "^/'"$base"'/"
{pri=
nt
> > $3,$5,$6} NR=3D=3D10{exit}'
>
> > to use a shell variable in the middle of your awk script. Don't do
that =
as
> > it
> > can lead to hard-to-diagnose failures, e.g.:
>
> as it happens i still haven't managed to get that variation going, so
i've=
> given up for now. i have only 3 cases for "base" in my current data
> collection, so it's simple enough to run three commands. this even has
som=
e
> other advantages relating to how i'll use the data.
>
> i guess it's instructive to me that this appears non-trivial (and even a
b=
it
> controversial?) in a language as mature as awk.
No, it is trivial. Any "non-triviality" here stems from shell
quoting issues and from mixing shell level and awk level code.
I also think it hasn't been controversial (at least comparing
suggestions amongst posters of a similar experience).
(Some non-trivialities will appear if your dynamic regexps
contains regexp meta-characters.)
(BTW, since it hasn't been mentioned yet; to avoid problems
with quoting you can put the awk program in a file and call
it using awk's -f option. As a side effect you are forced to
use a cleaner and more robust way to pass shell variables.)
Janis
>
> cheers,
>
> Tim


|