Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 exptools 1/6/84; site iham1.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!houxm!ihnp4!iham1!fcy From: fcy@iham1.UUCP (Fred Yankowski) Newsgroups: net.unix-wizards Subject: How to pass /bin/sh parameters into awk scripts Message-ID: <175@iham1.UUCP> Date: Fri, 3-Aug-84 10:06:49 EDT Article-I.D.: iham1.175 Posted: Fri Aug 3 10:06:49 1984 Date-Received: Sat, 4-Aug-84 02:48:02 EDT Organization: AT&T Bell Labs, Naperville, IL Lines: 33 The awk script presented in the original question about passing parameters to awk: awk "BEGIN{id=$2;}{ \ printf(\"%8d %s\n\", id++, \$0); \ }' $1 is missing an escape ('\') before the "\n". /bin/sh will remove the single escape when evaluating the double-quoted string before it is passed to 'awk'. A trick may be employed to avoid all the ugly quoting needed for the above example. The following performs the same function: awk " BEGIN {id=$2;} "' { printf ("%8d %s\n", id++, $0); } ' $1 This trick relies on the fact that /bin/sh treats "xxx"'yyy' as *one* "word": i.e. the contiguous strings are treated as one. This is useful for creating a single string, part of which is evaluated (within double quotes) and part of which is literal. In the above, the awk script through the BEGIN line is evaluated, the rest is literal. The 'awk' manual page talks about passing parameters via the command line, but I've never been able to make it work and the source for awk does not seem to attempt to obtain such parameters anyhow. Who knows? Fred Yankowski ::: AT&T Bell Laboratories ::: ihnp4!iham1!fcy IH 6B-216 x6902