[comp.unix.xenix] How do I print a single quote in AWK?

tuck@iris.ucdavis.edu (Devon Tuck) (03/08/90)

Here is a question for those of you out there who are familiar with 'awk':
I am having difficulties getting a single quote (') printed.  I have tried
using the printf, and print commands, as well as the sprintf() built-in.
The following is an example program which works, but does not print the
single quotes.  Intuitively, I would think that line 3 could be:

	printf "%-72sX\n","      INCLUDE '"(name = substr($0, 8, 6))".h'"

and that should do the trick -- but it doesn't :-(

##########################################################################
# Description: AWK program to change 
#
#|$ADD C.NAME
#
# to ...
#
#|C$ADD C.NAME                                                          HM
#|      INCLUDE 'NAME.h'                                                X      
#
# Note: the '|' is the beginning of a line of code in Fortran 77 and the
# letters to the right of the screen exist as flags in the 'safe' 73-80
# columns of a traditional fortran program.
##########################################################################
awk '/\$ADD C\./ {
	printf "%-72sHM\n","C"$1" "$2;
	printf "%-72sX\n","      INCLUDE "(name = substr($0, 8, 6))".h"
	}
	{
	# If there was no change, print out the line.
	print
}' awktest

Thanks for your help,
	Devon (tuck@ucdavis.edu)

itkin@mrspoc.Transact.COM (Steven M. List) (03/09/90)

tuck@iris.ucdavis.edu (Devon Tuck) writes:

>Here is a question for those of you out there who are familiar with 'awk':
>I am having difficulties getting a single quote (') printed.  I have tried
>using the printf, and print commands, as well as the sprintf() built-in.
>The following is an example program which works, but does not print the
>single quotes.  Intuitively, I would think that line 3 could be:

>	printf "%-72sX\n","      INCLUDE '"(name = substr($0, 8, 6))".h'"

>and that should do the trick -- but it doesn't :-(

>awk '/\$ADD C\./ {
>	printf "%-72sHM\n","C"$1" "$2;
>	printf "%-72sX\n","      INCLUDE "(name = substr($0, 8, 6))".h"
>	}
>	{
>	# If there was no change, print out the line.
>	print
>}' awktest

Do you suppose that the awk script is being included on the command
line with SINGLE QUOTES might affect what is being attempted?  Perhaps
if the script were either written to a temporary file first or if the
single quotes inside the awk script were escaped (preceded with back-
slashes) this script would work properly.  It's not AWK's problem, it's
the shell's (and the programmer's).
-- 
 +----------------------------------------------------------------------------+
 :                Steven List @ Transact Software, Inc. :^>~                  :
 :           Chairman, Unify User Group of Northern California                :
 :     {apple,coherent,limbo,mips,pyramid,ubvax}!itkin@guinan.Transact.COM    :