Single quote in sprintf / printf statements 
Author Message
 Single quote in sprintf / printf statements

Can someone tell me how to include single quotes in a
printf/sprintf statement as in:

  printf(" '%s' "), PARM

Thanks,

* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Sun, 04 Aug 2002 03:00:00 GMT  
 Single quote in sprintf / printf statements
Quote:

>Can someone tell me how to include single quotes in a
>printf/sprintf statement as in:

>  printf(" '%s' "), PARM

<snip>
If PARM is what you want to print then the code should be:

    printf("'%s'",PARM)

HTH
Peter
--


Opinions expressed are my own and not necessarily those
of my employer



Mon, 05 Aug 2002 03:00:00 GMT  
 Single quote in sprintf / printf statements
Like this:

        printf(" '%s' ", PARM )

if you are using a script file (i.e. *.awk).

If, on the other hand, you are writing this direct in the shell
then this is a shell problem and since you didn't specifiy what
OS (or shell under UNIX) you are using it makes it more difficult
to answer.

Ask and ye shall receiveth...
--
Best regards,
 _ __                      _    ,   _ _ _
' )  )     /         _/_  ' )  /   ' ) ) )
 /--' ____/___/> __  /     /--/     / / / __,_  __  o _   ______
/  \_(_) /_) (__/ (_<__   /  ( o   / ' (_(_) (_/ (_<_/_)_(_) / <_

Robert H. Morrison                      Tel:   +49 721 9628 167
Software Development, Basis Team        FAX:   +49 721 9628 149



Quote:
> Can someone tell me how to include single quotes in a
> printf/sprintf statement as in:

>   printf(" '%s' "), PARM

> Thanks,

> * Sent from RemarQ http://www.remarq.com The Internet's Discussion
Network *
> The fastest and easiest way to search and participate in Usenet - Free!



Mon, 05 Aug 2002 03:00:00 GMT  
 Single quote in sprintf / printf statements
Thanks for your responses.  I certainly did not state the problem
very well and in haste even my example (as you have all pointed
out) was faulty.

I have no problem with this working from within an awk script.
The problem is that I have included a small amount of awk code in
a shell script and the single quotes get stripped from the
output. I think that Robert Morrison in his response touches on
this issue. The OS is HP-UX.  Does anyone know of a solution?

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Mon, 05 Aug 2002 03:00:00 GMT  
 Single quote in sprintf / printf statements


...

Quote:
>output. I think that Robert Morrison in his response touches on
>this issue. The OS is HP-UX.  Does anyone know of a solution?

The standard method of including a single quote in a string in an AWK
script that is included in a shell script (in any version of Unix) is
to use \047.

E.g.

#!/bin/sh
awk 'BEGIN {print "He said, \047Hi!\047"}'



Mon, 05 Aug 2002 03:00:00 GMT  
 Single quote in sprintf / printf statements


% >  printf(" '%s' "), PARM
% >
% <snip>
% If PARM is what you want to print then the code should be:
%
%     printf("'%s'",PARM)

<nitpick>
either will work
</nitpick>
--

Patrick TJ McPhee
East York  Canada



Tue, 06 Aug 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Single and Double Quotes in Echo Statements

2. INCLUDE statements: use single or double quotes?

3. replace single quote to double quote with an example

4. single-quoted string conversion to triple-quoted string

5. Why doesn't the single quote charater show up in my printf statements output??

6. Single quotation in printf

7. printf statement

8. Not enough parameters for a printf statement

9. How to print out single quoted columns?

10. gawk win32 binary & single quote invalid char

11. Substituting single quotes from Perl via shell using awk and gsub

12. parsing lines with quoted strings as single fields

 

 
Powered by phpBB® Forum Software