AWK/shell quoting (was: Re: Access to UNIX-Related Publications)
David Elliott
dce at smsc.sony.com
Sun Jan 7 10:33:40 AEST 1990
In article <18067 at umn-cs.CS.UMN.EDU> mike at umn-cs.cs.umn.edu (Mike Haertel) writes:
>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.
...
>2. You can do it by cooperating with shell quoting. This is hairy,
>but will print a single quote:
>
> awk 'BEGIN {print "'"'"'"}'
Hopefully, people tend towards this solution. Some people I have
worked with like to put awk scripts in separate files. To me, that's
like breaking up your C program into separate binaries and exec'ing
them as needed - it slows down the program and makes it harder to
maintain.
One trick I use is to say
awk 'BEGIN {
Sq = "'"'"'";
and then use Sq wherever I need single quotes. Also, if you have
an awk that handles octal escapes in sprintf, you could use that
to put a single quote into Sq.
--
David Elliott
dce at smsc.sony.com | ...!{uunet,mips}!sonyusa!dce
(408)944-4073
"But Pee Wee... I don't wanna be the baby!"
More information about the Comp.unix.questions
mailing list