variables in awk

Jean-Pierre Radley jpr at dasys1.UUCP
Mon May 1 01:28:10 AEST 1989


In article <10029 at burdvax.PRC.Unisys.COM> lang at sirius.PRC.Unisys.COM (Francois-Michel Lang) writes:
>An AWK question for the resident wizards:
>Is there any way to do pattern-matching on an AWK variable?

Yes, why not?
>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.

Awk variables are valid anywhere in an awk script.
Maybe I'll just give you an example excerpted from some code of mine:

awk '
	   ...
$4!=Num	{
	   ...
	}
	{
	AccT+=$6; GT+=$6; ST+=$6; Num=$4
	   ...
	}
	   ...
'

At some point I set the variable Num equal to something. At some other
point, I test it.

Just do it.
-- 
Jean-Pierre Radley		Honi soit		jpr at dasys1.UUCP
New York, New York		qui mal			...!hombre!jpradley!jpr
CIS: 76120,1341			y pense			...!hombre!trigere!jpr



More information about the Comp.unix.questions mailing list