Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site rruxc.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!harvard!talcott!panda!genrad!decvax!harpo!whuxlm!whuxl!houxm!ihnp4!mhuxn!mhuxr!ulysses!gamma!pyuxww!pyuxv!rruxa!rruxo!rruxu!rruxc!alex From: alex@rruxc.UUCP (A DeSimone) Newsgroups: net.unix Subject: re: AWK question Message-ID: <104@rruxc.UUCP> Date: Fri, 9-Aug-85 11:10:26 EDT Article-I.D.: rruxc.104 Posted: Fri Aug 9 11:10:26 1985 Date-Received: Thu, 15-Aug-85 21:37:25 EDT References: <436@brl-tgr.ARPA> Organization: Bell Communications Research, Piscataway, NJ Lines: 41 > 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 Your problem is not with awk but with the shell's processing of your command line before passing it on the awk. The single quotes around the awk command turn off variable substitution (this is desired for $5 but NOT for $dt). The solution is to construct a command line that causes the shell to forego variable substitution for $5 but to perform it for $dt. The following works for me (SVr2) and should work for you too (the first 3 lines are yours): echo 'enter date in format yy-mm-dd \c $dt' read dt echo $dt # enclose date in double quotes so awk takes it as a string dt="\"$dt\"" # build awk command line on the fly awk '$5'" >= $dt " .suspfile >x.out BTW, ">=" does a *greater than or equal* not *less that or equal* (I assume this was a typo). Note that the date you "pass" to awk has to be in double quotes so that awk will take it as a string rather than a number. To avoid further confusion in the command line with still more double quotes, I've done that in advance of the awk invocation. ->"So it goes." ->Alex DeSimone, Amala Consultants Inc. @ Bell Communications Research ->..!ihnp4!rruxc!alex