Thread View: comp.unix.shell
3 messages
3 total messages
Started by Binod K. Taterway
Wed, 28 Nov 1990 15:52
A question on [a,ga,na]wk.
Author: Binod K. Taterway
Date: Wed, 28 Nov 1990 15:52
Date: Wed, 28 Nov 1990 15:52
20 lines
1210 bytes
1210 bytes
Is it possible to make use of c-shell variables in [g,n]awk scripts.
What I need to do some thing like this:
#!/bin/csh
set AWK=/usr/local/bin/gawk
set date=`date +%m/%d/%y`
# Now the awk script that uses $date:
$AWK -F: '{if ($3 == $date) {print $0}}' <source-file>
# End of shell script.
I checked with [g,n]awk. Only gawk can access environment variables,
but I do not want to do "setenv date= ..", just "set date= ..". Any
suggestions? Or, am I stuck with using setenv?
Thanks in advance.
/Binod.
--------------------
Binod Taterway bt00@pl118a.cc.lehigh.edu | bt00@lehigh.bitnet
User Consultant, Lehigh University, Bethlehem, PA 18015 (215) 758-3984
Re: A question on [a,ga,na]wk.
Author: Arnold Robbins
Date: Fri, 30 Nov 1990 19:39
Date: Fri, 30 Nov 1990 19:39
28 lines
1642 bytes
1642 bytes
In article <BT00.90Nov28155200@PL118d.?> bt00@PL118d.? (Binod K. Taterway) writes:
>Is it possible to make use of c-shell variables in [g,n]awk scripts.
>What I need to do some thing like this:
>
> #!/bin/csh
> set AWK=/usr/local/bin/gawk
> set date=`date +%m/%d/%y`
> # Now the awk script that uses $date:
> $AWK -F: '{if ($3 == $date) {print $0}}' <source-file>
> # End of shell script.
You can do variable assignments to awk variables on the command line.
The behaviour is most consistent with gawk and very recent versions of
nawk, but this should work with all awk variants:
set date=`date +%m/%d/%y`
$AWK -F: '{if ($3 == date) {print $0}}' date="$date" <source-file>
Of course, your awk program might better be written as
$AWK -F: '$3 == date' date="$date" <source-file>
See the gawk manual for full details on the way the awk command line works.
--
Arnold Robbins AudioFAX, Inc. | Laundry increases
2000 Powers Ferry Road, #200 / Marietta, GA. 30067 | exponentially in the
INTERNET: arnold@audiofax.com Phone: +1 404 933 7612 | number of children.
UUCP: emory!audfax!arnold Fax-box: +1 404 618 4581 | -- Miriam Robbins
Re: A question on [a,ga,na]wk.
Author: Walter Bays
Date: Fri, 14 Dec 1990 01:53
Date: Fri, 14 Dec 1990 01:53
22 lines
1140 bytes
1140 bytes
In article <BT00.90Nov28155200@PL118d.?> bt00@PL118d.? (Binod K. Taterway) writes:
>Is it possible to make use of c-shell variables in [g,n]awk scripts.
I often do it like...
#!/bin/ksh
Tempfile="c4sim.tmp$$"
...
nawk '
...
print ... >$Tempfile
...
' "Tempfile=$Tempfile" "Version=$Version" $*
---
Walter Bays Phone (415) 852-2384 FAX (415) 856-9224
EMAIL walter@apd.ingr.com
USPS: Intergraph APD, 2400 Geng Road, Palo Alto, California 94303
--
Walter Bays Phone (415) 852-2384 FAX (415) 856-9224
EMAIL walter@apd.ingr.com or ...!ingr!apd!walter
USPS: Intergraph APD, 2400 Geng Road, Palo Alto, California 94303
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads