Operating System - HP-UX
1827298 Members
2754 Online
109961 Solutions
New Discussion

Get awk to print single quotes character

 
Ian McClement_1
Occasional Advisor

Get awk to print single quotes character

I know the question has been asked many times
before, but can someone remind me how to get awk to print the single quote character.
ie. echo string| awk_text resulting in 'string'
Have tried the usual
echo string|awk '{print "\'"$1}' combinations

Cheers
Ian
2 REPLIES 2
Robin Wakefield
Honored Contributor

Re: Get awk to print single quotes character

Hi Ian,

here you go:

echo hello | awk '{print "'\''" $1 "'\''"}'
'hello'

Rgds, Robin
Graham Cameron_1
Honored Contributor

Re: Get awk to print single quotes character

Alternatively:

echo hello | awk '{print "\047" $1 "\047"}'
Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done.