AWK question
W. H. Pollock x4575 3S235
whp at cbnap.UUCP
Sat Aug 10 04:05:02 AEST 1985
>>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?
More information about the Comp.unix.wizards
mailing list