A question on [a,ga,na]wk.

Wm E. Davidsen Jr davidsen at sixhub.UUCP
Sun Dec 9 13:29:50 AEST 1990


  I missed the first part of this, but in general you can't use shell
variables in ' quotes because they don't get expanded.

This fails:

	awk '/$1 == $date/{ print $4 }' file

These work:
	awk "/\$1 == $date/{ print \$4 }" file
	awk '/$1 == date/{ print $4}' date=$date file

  The first allows substitution of the $date, but uses escapes to pass
the $ to awk (and you need escapes for any " quotes, too. The second is
the better way to do it, by defining an awk variable on the command
line.

NOTE: some versions of awk will not accept command line definitions
unless there is a filename. If you are reading stdin you must put a - in
for the filename:
	something | awk '/$1 == date/{ print $4}' date=$date -

  I hope that's what people were trying to say, the original question is
either behind the answers or very old. I have 10 days spooled and I
don't have it.
-- 
bill davidsen - davidsen at sixhub.uucp (uunet!crdgw1!sixhub!davidsen)
    sysop *IX BBS and Public Access UNIX
    moderator of comp.binaries.ibm.pc and 80386 mailing list
"Stupidity, like virtue, is its own reward" -me



More information about the Comp.unix.shell mailing list