printing of the character : ' 
Author Message
 printing of the character : '

Hey
I'd like to do an awk-program which prints the following:
                     '1'
But with a program like awk ' {print " '1' "} ' data I get just <space>1<space>
Also awk ' {print " \' 1 \' " } ' data does not the right result.

I hope someone could handle this little problem!
Ulrich

--
_____________________________________________________________
NewsGroups Suchen, lesen, schreiben mit http://www.*-*-*.com/



Mon, 18 Aug 2003 23:21:46 GMT  
 printing of the character : '

Quote:

> Hey
> I'd like to do an awk-program which prints the following:
>                      '1'
> But with a program like awk ' {print " '1' "} ' data I get just <space>1<space>
> Also awk ' {print " \' 1 \' " } ' data does not the right result.

Hello,
for chars like "'", which could make problems, just use a variable:
awk -v mark="'" -v dmark='"' '{print dmark,"string",dmark,mark,1,mark}'

mfg nik

Quote:

> I hope someone could handle this little problem!
> Ulrich

> --
> _____________________________________________________________
> NewsGroups Suchen, lesen, schreiben mit http://netnews.web.de

--
Top misuses of mathematics in real life:
        - incomplete induction
        - the application of probabilities on special cases


Tue, 19 Aug 2003 00:52:51 GMT  
 printing of the character : '

bash-2.04$ awk 'BEGIN{print "'\''1'\''"}'
'1'
That is:
1. terminate the first single quote (the one at the beginning of the script)
2. put in a backslash-escaped single quote (which the shell will interpret as a
literal single quote, and which will be passed to Awk as such)
3. If you want Awk to interpret the value in the 'print' list (i.e. a variable),
surround it in single quotes as I have done here
4. Repeat step 2
5. Put in another single quote (to balance out the one in step 1)
6. If you want 'print' to print a literal, the double quotes surrounding all of this
are needed.
Shell quoting is a mess, and I always have to think through it in the way I've
described.
Now to sit back and wait to hear where I've gone wrong :-)

Quote:


> > Hey
> > I'd like to do an awk-program which prints the following:
> >                      '1'
> > But with a program like awk ' {print " '1' "} ' data I get just <space>1<space>
> > Also awk ' {print " \' 1 \' " } ' data does not the right result.

> Hello,
> for chars like "'", which could make problems, just use a variable:
> awk -v mark="'" -v dmark='"' '{print dmark,"string",dmark,mark,1,mark}'

> mfg nik

> > I hope someone could handle this little problem!
> > Ulrich

> > --
> > _____________________________________________________________
> > NewsGroups Suchen, lesen, schreiben mit http://netnews.web.de

> --
> Top misuses of mathematics in real life:
>         - incomplete induction
>         - the application of probabilities on special cases



Tue, 19 Aug 2003 02:09:11 GMT  
 printing of the character : '

The best way to do this is to use \047, as in:

    awk 'BEGIN { print "\047" }'



Tue, 19 Aug 2003 02:31:35 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Printing 'non printable' Characters

2. Prints 'junk' characters

3. (subtypep '(simple-array character (*)) '(array character (*)))

4. Can't print national characters in IDLE with Python 2.2.1c1

5. ASCII Print Control Characters for printing with REXX/2

6. Summer '87 Print Output To Print Manager??

7. Handling of 'national characters' in strings

8. Writing 'strange' characters

9. putting strings in 'UPPER' characters

10. ADVANCE='NO', implied DO, CHARACTER array

11. '"""' and linefeed characters

12. Send true '\r' character with expect

 

 
Powered by phpBB® Forum Software