[net.unix-wizards] AWK question

ddaly%xls-plexus01.amc@AMC-HQ.ARPA (DUSTY) (08/05/85)

Does anyone know if and how I can get awk to do a >= (less than or equal)
on a value entered from a terminal by the user?
E.G.
echo 'enter date in format yy-mm-dd \c $dt'
read  dt
echo $dt
awk '$5  >= $dt ' .suspfile >xout

awk seems to ignore the terminal entered data. Is there any way to get
awk to recognize this kind of variable?

ed daly
ddaly at amc-hq

dpn@panda.UUCP (Dale P. Nielsen) (08/06/85)

In article <435@brl-tgr.ARPA> ddaly%xls-plexus01.amc@AMC-HQ.ARPA (DUSTY) writes:
>Does anyone know if and how I can get awk to do a >= (less than or equal)
>on a value entered from a terminal by the user?
>E.G.
>echo 'enter date in format yy-mm-dd \c $dt'
>read  dt
>echo $dt
>awk '$5  >= $dt ' .suspfile >xout
>
>awk seems to ignore the terminal entered data. Is there any way to get
>awk to recognize this kind of variable?
>
>ed daly
>ddaly at amc-hq

How about:

awk '$5 >= "'"$dt"'"' .suspfile >xout

this way the shell variable $dt get translated before awk gets it.

-- 

					--Dale P. Nielsen


"Well, that's all fuel under the reactor now, Mr. Time!"

peter@kitty.UUCP (Peter DaSilva) (08/07/85)

> echo 'enter date in format yy-mm-dd \c $dt'
> read  dt
> echo $dt
awk '$5 >= '"$dt"...			#########
> awk '$5  >= $dt ' .suspfile >xout
> 
> awk seems to ignore the terminal entered data. Is there any way to get
> awk to recognize this kind of variable?

Enclose it in quotes that don't over-ride variable substitution.

ken@turtlevax.UUCP (Ken Turkowski) (08/07/85)

In article <435@brl-tgr.ARPA> ddaly%xls-plexus01.amc@AMC-HQ.ARPA (DUSTY) writes:
>Does anyone know if and how I can get awk to do a >= (less than or equal)
>on a value entered from a terminal by the user?
>E.G.
>echo 'enter date in format yy-mm-dd \c $dt'
>read  dt
>echo $dt
>awk '$5  >= $dt ' .suspfile >xout

Have you tried using double quotes instead of single quotes? Try:
	awk "$5  >= $dt " .suspfile >xout
-- 

Ken Turkowski @ CADLINC, Menlo Park, CA
UUCP: {amd,decwrl,hplabs,nsc,seismo,spar}!turtlevax!ken
ARPA: turtlevax!ken@DECWRL.ARPA

whp@cbnap.UUCP (W. H. Pollock x4575 3S235) (08/09/85)

>>Does anyone know if and how I can get awk to do a >= (less than or equal)
>>on a value entered from a terminal by the user?
>>E.G.
>>echo 'enter date in format yy-mm-dd \c $dt'
>>read  dt
>>echo $dt
>>awk '$5  >= $dt ' .suspfile >xout
>
>Have you tried using double quotes instead of single quotes? Try:
>	awk "$5  >= $dt " .suspfile >xout

Wrongo!  This won't work since the shell will substitute for the $5 as well!
A more correct version is:

	awk '$5 >= '$dt .suspfile >xout

The spacing around the quotes is critical.  Also, you may have a problem if
awk thinks $5 is a string and $dt is a number (or vice versa).  To force
numeric comparision, use:

	awk '$5 + 0 >= '$dt' + 0' .suspfile >xout

To force string comparision, use:

	awk '$5 "" >= '$dt' ""' .suspfile >xout

It is possible to set an awk variable on the command line, and avoid fooling with
the quotes.

Wayne Pollock
PS why don't you use sed (or cut) and test instead?

paulh@tektronix.UUCP (Paul Hoefling) (08/10/85)

In article <435@brl-tgr.ARPA> ddaly%xls-plexus01.amc@AMC-HQ.ARPA (DUSTY) writes:
>> Does anyone know if and how I can get awk to do a >= (less than or equal)
>> on a value entered from a terminal by the user?
>> E.G.
>> echo 'enter date in format yy-mm-dd \c $dt'
>> read  dt
>> echo $dt
>> awk '$5  >= $dt ' .suspfile >xout
>> 
>> awk seems to ignore the terminal entered data. Is there any way to get
>> awk to recognize this kind of variable?
>
> How about:
>
> awk '$5 >= "'"$dt"'"' .suspfile >xout
>
> this way the shell variable $dt get translated before awk gets it.

How about just:

awk "\$5 >= $dt" .suspfile >xout

-- 

Paul Hoefling
Information Pack Rat
uucp: {allegra,decvax,ihnp4,ucbvax,zehntel}!tektronix!paulh

bill@ima.UUCP (08/11/85)

![?	HI always like to put my awk scripts inside single quotes, to keep things&simple.  This is another way to do it: