AWK/shell quoting (was: Re: Access to UNIX-Related Publications)

Mike Haertel mike at umn-cs.CS.UMN.EDU
Sun Jan 7 04:56:40 AEST 1990


In article <166 at omaha1.UUCP> wcc at omaha1.UUCP (William C Carey) writes:
>Any of the luminaries out there know how to get 'awk' (not nawk) to ouput a
>single-quote character ( ascii 0x27 ).  I can't get the 'print' or
>the 'printf' statement to do it with any combination of backslashes,
>double-quotes, or percent characters.

Your problem is that you are embedding the awk program in a quoted
shell string, and the single quotes you are trying to use in the awk
program are interacting with the shell's quoting conventions.

There are 2 solutions:

1.  You can move the awk program to a file, foo.awk, and then merely
say "awk -f foo.awk" in the shell program.  Then an awk program
to print a single quote would look like:

	BEGIN {print "'"}

2.  You can do it by cooperating with shell quoting.  This is hairy,
but will print a single quote:

	awk 'BEGIN {print "'"'"'"}'

Breaking it down we see that the argument to awk consists of three
concatenated shell-quoted strings:

	'BEGIN {print "'  "'"  '"}'
-- 
Mike Haertel <mike at ai.mit.edu>
"Of course, we have to keep in mind that this year's Killer Micro
 is next year's Lawn Sprinkler Controller . . ." -- Eugene Brooks



More information about the Comp.unix.wizards mailing list