Xref: utzoo comp.unix.questions:18834 comp.unix.wizards:20030 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!shadooby!samsung!zaphod.mps.ohio-state.edu!wuarchive!decwrl!shelby!lindy!forel!karish From: karish@forel.stanford.edu (Chuck Karish) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: AWK/shell quoting Message-ID: <6954@lindy.Stanford.EDU> Date: 7 Jan 90 15:38:11 GMT References: <487@longway.TIC.COM> <166@omaha1.UUCP> <18067@umn-cs.CS.UMN.EDU> <1990Jan6.233340.9978@smsc.sony.com> <2367@leah.Albany.Edu> Sender: news@lindy.Stanford.EDU (News Service) Reply-To: karish@forel.stanford.edu (Chuck Karish) Organization: Mindcraft, Inc. Lines: 48 In article <2367@leah.Albany.Edu> emb978@leah.Albany.EDU.UUCP (Eric M. Boehm) wrote: >In article <18067@umn-cs.CS.UMN.EDU> mike@umn-cs.cs.umn.edu >(Mike Haertel) writes: >>In article <166@omaha1.UUCP> wcc@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 ). >>2. You can do it by cooperating with shell quoting. This is hairy, >>but will print a single quote: >> >> awk 'BEGIN {print "'"'"'"}' > >This solutions seem to be overly complex. Maybe I'm picking nits but >wouldn't this be easier and simpler? > >awk 'BEGIN { print "\'" }' Have you tried it? % awk 'BEGIN { print "\'" }' Unmatched ". % sh $ awk 'BEGIN { print "\'" }' > > ' > " awk: newline in string }'... at source line 1 context is BEGIN { print "\ }' >>> <<< awk: syntax error at source line 3 awk: illegal statement at source line 3 missing } Here's what those nested quotes do: awk 'BEGIN {print "'"'"'"}' 1234321 1) Usual quotes to set off a constant string for the 'print' directive 2) Match the single quotes that set off the whole awk script; text within is interpreted by the shell. 3) Quotes to protect the data from interpretation by the shell. 4) The data, to be printed unchanged. Chuck Karish karish@mindcraft.com (415) 323-9000 karish@forel.stanford.edu