1752755 Members
5286 Online
108789 Solutions
New Discussion юеВ

awk printing ' character

 
SOLVED
Go to solution
Gavin Clarke
Trusted Contributor

awk printing ' character

How do I print ' as part of an awk command, I can't seem to find the right way to do it.

ls | awk '{print "'" $1 "'"}' just doesn't work.

Thanks very much in anticipation of some stunning insights.
17 REPLIES 17

Re: awk printing ' character

Hi try

awk '{print $x}'

where x is the field number of your command
Pete Randall
Outstanding Contributor

Re: awk printing ' character

awk '{ print $1 }'

should work. Cut and paste it to make sure you get the spacing right.


Pete


Pete
john korterman
Honored Contributor

Re: awk printing ' character

Hi,
the only way I can think of:
# echo hello | awk -v flip="\'" '{print flip $1 }'

regards,
John K.
it would be nice if you always got a second chance
Gavin Clarke
Trusted Contributor

Re: awk printing ' character

Sorry that's not going to work. I need to print the character ' round either side of the filename ($1).

Thanks for a quick reply though.
Gavin Clarke
Trusted Contributor

Re: awk printing ' character

That flip line seems to do the trick.

Hmmm got out of sequence a bit there.
Pete Randall
Outstanding Contributor

Re: awk printing ' character

Gavin,

Sorry - I missed that you're trying to print the apostrophe. Working . . .


Pete


Pete
john korterman
Honored Contributor
Solution

Re: awk printing ' character

sorry,
should of course have been:
# ls | awk -v flip="\'" '{print flip $1 flip }'

regards,
John K.
it would be nice if you always got a second chance
curt larson_1
Honored Contributor

Re: awk printing ' character

have you tried:
print "\'" $1 "\'";
or
printf("'%s'\n",$1);
James R. Ferguson
Acclaimed Contributor

Re: awk printing ' character

Hi Gavin:

# ls -l /tmp/me|awk '{print "'\''" $NF "'\''"}'

Regards!

...JRF...