Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!aimt!breck From: breck@aimt.UUCP (Robert Breckinridge Beatie) Newsgroups: comp.unix.questions Subject: Re: An awk question or two... Message-ID: <90@aimt.UUCP> Date: Mon, 14-Sep-87 22:04:48 EDT Article-I.D.: aimt.90 Posted: Mon Sep 14 22:04:48 1987 Date-Received: Wed, 16-Sep-87 05:38:36 EDT References: <3931@well.UUCP> <27817@sun.uucp> Distribution: na Organization: AIM Technology, Palo Alto, CA Lines: 33 Keywords: awk ranges Summary: Another legal pattern In article <27817@sun.uucp>, guy@sun.uucp (Guy Harris) writes: > > awk -f comline.awk comvar=\"SUB\" ascii.h > > > > this is the file comline.awk: > > > > comvar { print } > > > > "comvar" is not a legal pattern. A pattern is either a keyword (such as BEGIN > or END), a relational expression, or a regular expression. You can't just > throw a variable name there and expect "awk" to treat that as a regular > expression that matches all lines that contain that regular expression; "awk" > doesn't permit that. > Actually, according to: "Awk - A Pattern Scanning and Processing Language" by Aho Kernighan and Weinberger (Second Edition), "A variety of expressions may be used as patterns: regular expressions, arithmetic relational expressions, *string-valued expressions*, and arbitrary boolean combinations of these." Now I haven't been able to make use of variables as "string-valued expressions" in the pattern part of an awk statement, but I haven't been able to find anything that says they can't be. In fact in the action part of an awk statement, a variable is a valid string-valued expression, so shouldn't it also be valid in the pattern part of the statement? I think the question boils down to, "How can I force awk to use the value of the variable: comvar instead of the string that is the variable's name?" Or is my interpretation of documentation flawed? God knows I've been bitten by my too-liberal interpretation of documentation before. -- Breck Beatie uunet!aimt!breck