Article View: alt.lang.awk
Article #32Re: Calling AWK function from within SC as a macro !!
From: tbates
Date: Tue, 08 Jun 1993 00:55
Date: Tue, 08 Jun 1993 00:55
57 lines
2800 bytes
2800 bytes
Vilok,
I think the problem may be confusion about shell parameter use in awk.
The $1 on the command line would be the input file to the awk program. The $1
in the awk program would be the first field in the input file. I don't believe
this is what you intended.
Try this:
awk -v "date=$1" 'BEGIN {print (substr(date,1,2)+((substr(date,4,2)-1)*30)+((sub
str(date,7,2)-92)*365))}'
-v causes awk to assign an awk variable prior to execution of the awk
program.
"date=$1" assigns the awk variable date to the shell parameter $1.
Placing your awk program within a BEGIN section makes all this happen
without reading an input file.
Please note how date is used within the substr's; instead of $1.
I hope this helps.
Sincerely,
Tom
In article <1993Jun7.180006.2670@bmerh85.bnr.ca>, vilok@bmerh322.bnr.ca (Vilok Kusumakar) writes:
> Has anybody used @ext(se, e) feature of SC - the spreadsheet calculator ?
> I am trying to call an awk script "days" like this
>
> @ext(days, C1)
>
> where cell C1 has data in the format - 01/05/92
>
> The "days" script looks like this
>
> awk '{print (substr($1,1,2)+((substr($1,4,2)-1)*30)+((substr($1,7,2)-92)*365))}' $1
>
> It converts the above date format into number of days since 1/1/92. I
> think the problem is that C1 is not getting passed as $1 to this awk
> script. In @ext(se, e), how does "e" gets passed to external function
> "se" ?
>
> Any help will be appreciated.
>
> --
> Vilok Kusumakar OSI Protocols for tomorrow......
> vilok@bnr.ca Bell-Northern Research, Ltd.
> Phone: (613) 763-2273 P.O. Box 3511, Station C
> Fax: (613) 765-4777 Ottawa, Ontario, K1Y 4H7
--
Tom Bates IBM Austin
My opinions are my own. email: tbates@austin.ibm.com
"Tom, we need that Design Specification NOW! But captain, I'm typing
as fast as I can!"
Technical Details
Message-ID:
<C8A2KI.GB6@austin.ibm.com>Path:
arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!cs.utexas.edu!geraldo.cc.utexas.edu!portal.austin.ibm.com!awdprime.austin.ibm.com!tbatesReferences:
<1993Jun7.180006.2670@bmerh85.bnr.ca>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109023,93d2274a30211d1e X-Google-Attributes: gid109023,public X-Google-Thread: 14b500,93d2274a30211d1e X-Google-Attributes: gid14b500,public X-Google-ArrivalTime: 1993-06-07 18:06:29 PST Newsgroups: alt.lang.awk,bnr.unix Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!howland.reston.ans.net!math.ohio-state.edu!cs.utexas.edu!geraldo.cc.utexas.edu!portal.austin.ibm.com!awdprime.austin.ibm.com!tbates From: tbates@austin.ibm.com () Subject: Re: Calling AWK function from within SC as a macro !! Originator: tbates@rama.austin.ibm.com Sender: news@austin.ibm.com (News id) Message-ID: <C8A2KI.GB6@austin.ibm.com> Date: Tue, 8 Jun 1993 00:55:29 GMT References: <1993Jun7.180006.2670@bmerh85.bnr.ca> Organization: IBM Austin Lines: 57