Import variables in to awk.
David C Lawrence
tale at pawl.rpi.edu
Thu Nov 16 10:55:18 AEST 1989
In <10531 at thorin.cs.unc.edu> warner at unc.cs.unc.edu (Byron Warner) writes:
Byron> [file foo]
Byron> { print import,$0 }
Byron> [command]
Byron> awk -F: -f foo /etc/passwd import='hello
Byron> why do I get just a list of logins?
Because the variable assignment has to come before file name. I'm
also assuming here that the ' is a typo, or the absence of a match is;
either way variable assignment comes before the file list. If you
change it to "awk -F: -f foo import=hello /etc/passwd" it will work.
This applies to V7 awk, nawk and gawk.
In <20774 at mimsy.umd.edu> chris at mimsy.umd.edu (Chris Torek) writes:
Chris> All of the above is with respect to the 4.3BSD flavour of `awk'. The
Chris> new awk (as described in the awk book) appears to open the first `file'
Chris> before executing the BEGIN statement, so that any assignments that
Chris> appear before the first real file happen before the BEGIN. What GNU
Chris> awk does, I do not know (but the above technique will tell you).
Variables set as above are not available in the BEGIN block with gawk,
but a special option, -v, is provided to do this. -v VAR=VAL will
assign VAL to VAR before script execution begins; another -v must be
specified for each variable you want to declare this way.
Dave
--
(setq mail '("tale at pawl.rpi.edu" "tale at ai.mit.edu" "tale at rpitsmts.bitnet"))
More information about the Comp.unix.questions
mailing list