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

stuart at siesoft.co.uk stuart at siesoft.co.uk
Sat Dec 8 04:21:09 AEST 1990


fuchs at it.uka.de (Harald Fuchs) writes:

>Solution 2, works for every awk:
>Take $date out of the single quotes
>  #!/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.
>The double quotes are not necessary, but they will be if $date contains
>shell-metacharacters (e.g. spaces).

My first reaction to this was that the double quotes are always necessary
because otherwise awk treats it as an awk variable (if $data were "jan",
say, then awk would try and match $1 with the contents of jan).  I think
this is true on most (if not all) versions of awk.

There is however another mistake in that the single and double quotes are
the wrong way round, you are telling awk that $date is a string, not csh.
So it should be:

...
$AWK -F: '{if ($3 == "'$date'") {print $0}}' <source-file>
...

>Harald Fuchs <fuchs at it.uka.de> <fuchs%it.uka.de at relay.cs.net> ...
><fuchs at telematik.informatik.uni-karlsruhe.dbp.de>   *gulp*

Stuart.
-
--
S I E M E N S  Stuart Hood 65-73 Crockhamwell Road, Woodley, Berkshire, UK
-------------  Phone: + 44-734-691994          Email: stuart at siesoft.co.uk
N I X D O R F  The trouble with everyone, is that they generalise too much



More information about the Comp.unix.shell mailing list