Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!labrea!decwrl!sun!guy From: guy@sun.UUCP Newsgroups: comp.unix.questions Subject: Re: An awk question or two... Message-ID: <27817@sun.uucp> Date: Sat, 12-Sep-87 02:14:57 EDT Article-I.D.: sun.27817 Posted: Sat Sep 12 02:14:57 1987 Date-Received: Sun, 13-Sep-87 08:16:22 EDT References: <3931@well.UUCP> Distribution: na Organization: Sun Microsystems, Inc. - Mtn View, CA Lines: 33 Keywords: awk ranges > awk -f comline.awk comvar=\"SUB\" ascii.h > > this is the file comline.awk: > > comvar { print } > > and, the result: > > 323 bin/src :-} !aw > awk -f comline.awk comvar=\"SUB\" ascii.h > awk: syntax error near line 1 > awk: bailing out near line 1 > 324 bin/src :-} "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. What you want to do instead is to pass the program to "awk" *on the command line*, and put it in double quotes so that shell variables are expanded before the string is passed to "awk". E.g., in a shell script, you could have the command: awk "/$1/ { print }" ... which would tell "awk" to print whatever lines were matched by the pattern specified by the first argument to that shell script. -- Guy Harris {ihnp4, decvax, seismo, decwrl, ...}!sun!guy guy@sun.com (or guy@sun.arpa)