variables in awk

Francois-Michel Lang lang at sirius.PRC.Unisys.COM
Thu Apr 27 01:29:39 AEST 1989


An AWK question for the resident wizards:
Is there any way to do pattern-matching on an AWK variable?

E.g., if I want to do something every time I find a line
containing the string "foo", I can say

/foo/ { ... <ACTION> ... }

Similarly, if I want to do something every time I find a line
whose third word contains the string "foo", I can do

$3 ~ /foo/ { ... <ACTION> ... }

Now, the question is, what if I want to match not against
a given string (which is fixed at "compile time"),
but against an AWK variable, whose value can change
in the course of the life of the AWK script.
I can't find anything in any AWK documentation
that tells me that this is possible, and, if so,
how to do it.  Any pointers would be appreciated.
----------------------------------------------------------------------------
Francois-Michel Lang
Paoli Research Center, Unisys Corporation lang at prc.unisys.com (215) 648-7256
Dept of Comp & Info Science, U of PA      lang at cis.upenn.edu  (215) 898-9511



More information about the Comp.unix.questions mailing list