Re: passing variables to gawk

From: Kenny McCormack (gazelle_at_yin.interaccess.com)
Date: 03/04/05


Date: Fri, 04 Mar 2005 22:53:02 GMT

In article <2v5Wd.1026$0b6.911@news.cpqcorp.net>,
Robert Katz <katz@hp.com> wrote:
>Ed Morton wrote:
>>
>>
>> Kenny McCormack wrote:
>>
>>> In article <0ZudncxBefjKGrXfRVn-pQ@comcast.com>,
>>> Ed Morton <morton@lsupcaemnt.com> wrote:
>>> ...
>>>
>>>>>> As long as you don't need them in the BEGIN section, ARGV[] would
>>>>>> give you what you appear to want, e.g.:
>>>>>>
>>>>>> awk '{
>>>>>> print "X = " X ", Y = " Y ", Z = " Z
>>>>>> for (q=1; q<ARGC; q++) print ARGV[q]
>>>>>> }' X=a Y=b Z=c file
>>>>>
>>>>>
>>>>>
>>>>> Not if you are using "-v" - which is the whole point.
>>>>
>>>>
>>>> There's nothing in the original posting requiring you to use "-v" -
>>>> you just assumed that based on the example given and kicked off a
>>>> chain of postings about using "-v". That doesn't mean that using "-v"
>>>> is the only option availabe to the OP.
>>>>
>>>>
>>>>> (Yes, I understand, your comment: "As long as you don't need them in
>>>>> the
>>>>> BEGIN section" is an attempt to eliminate this requirement)
>>>>
>>>>
>>>> There is no requirement to eliminate.
>>>
>>>
>>>
>>> Which part of:
>>>
>>> :If I do
>>>
>>> : gawk -v X=a -v Y=b ... '{ ... }'
>>>
>>> :does the gawk program know how many and which variables were passed
>>> to it?
>>>
>>> are you having a problem with?
>>
>>
>> It's an EXAMPLE. But you're absolutely right as always - just because we
>> know an approach that appears to solve the OPs problem is no excuse for
>> posting it if it doesn't precisely match the posted attempt that
>> absolutely cannot work.
>>
>>> Let's an analogy:
>>>
>>> Q: If I jump off a high bridge, will I be injured?
>>> A: No. Because in my re-interpretation of your question, you don't
>>> jump off the bridge. In fact, you stay home safely in bed.
>>
>>
>> Excellent analogy. I assume your response would be "yes, and here's how
>> to do it..." while some of us might try to understand what problem the
>> OP is really trying to solve and thereby suggest taking the stairs to
>> the bottom.
>>
>> Ed.
>
>An admirable, exceptionally good, and rational approach, Ed, and indeed
>I may be able to work around the requirement of needing the values in
>the BEGIN section. Thanks!

My view (and think of this as an answer to Ed's more recent post as well)
is that the problem is only interesting if it has to be solved in the "-v"
(and thus most likely this implies "need it in the BEGIN clause" as well)
case. Thus, I chose to interpret the problem in the way that:
        a) It was stated
and b) Makes it an interesting problem
and c) Doesn't insult the poster's intelligence (see below)

P.S. Anyone with an IQ over room temperature could solve it in the non -v
case. I presume all of us here meet this criterion.

P.P.S. By the way, Ed, glad you liked my analogy. I stand by it.



Relevant Pages

  • Re: movin on. Auld Lang Sygne
    ... >> threats, RL attacks, posting of private info, attacking families, ... And like Morton, their ... talking to him and agreeing with his attacks on Jite. ...
    (alt.support.chronic-pain)
  • Re: Pictures from the OpenVMS bootcamp
    ... law in the U.S.A. ... Telling other people to comply doesn't excuse ... permission FIRST, and only make those images public when the ... Z. Lederman Personal Opinions Only Posting to a News group does NOT give anyone permission to send me advertising by E-mail or put me on a mailing list of any kind. ...
    (comp.os.vms)
  • Re: Official release of the Twelve Assembly Lessons
    ... whats your excuse? ... i refrain from posting when i am drunk. ... from having to apopogize. ... suggest that your self confessed drinking hours are probably far more ...
    (alt.lang.asm)
  • Re: OT Food hoarding starts
    ... oil, etc because of being bought out I guess, what's this pointing at? ... And excuse the OT, just curious... ...
    (alt.support.chronic-pain)
  • Re: OT- computer info needed for Windows XP
    ... Ummm,please excuse but, some idiot sonofabitch has hacked a few Screen ... names from alt.native & is posting everywhere using our names. ... wayne george was also hacked. ...
    (rec.sport.billiard)