Operating System - HP-UX
1752562 Members
4731 Online
108788 Solutions
New Discussion юеВ

Re: awk printing ' character

 
SOLVED
Go to solution
Gavin Clarke
Trusted Contributor

Re: awk printing ' character

I did try using printf, I still had problems.

If flip doesn't work then I'll give it another go.
Jean-Luc Oudart
Honored Contributor

Re: awk printing ' character

I had same issue a while ago
#!/bin/sh

QUOT="'"

echo " " | awk -v quot=$QUOT '
{ print quot,quot,"abcd",quot,quot;}'

just an example.

Rgds,
Jean-luc
fiat lux
Gavin Clarke
Trusted Contributor

Re: awk printing ' character

Whoa, thanks for all the responses. After some fiddling I got what I wanted, which was a little more complicated than the example I gave (but not alot).

I adopted the "'\''" approach after I'd cut and paste it into notepad to see what was actually going on, seemed to fit well with what I was doing.
James R. Ferguson
Acclaimed Contributor

Re: awk printing ' character

Hi (again) Gavin:

For clarity later, the post of mine you used:

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

is garbled badly when it is displayed here. For reference, the character sequence is:

...print $NF singlequote> )

Regards!

...JRF...
karthik3152
New Member

Re: awk printing ' character

do it this way

ls | awk '{print $1}'


For clearer explanation go through the AWK PROGRAMMING MODEL
which explains how the awk works
http://linux-forum-karthik.blogspot.com/2011/05/awk-programming-model.html

and go through the awk variables usuage

http://linux-forum-karthik.blogspot.com/2011/05/awk-variables.html

Above links will be useful in learning the same.







Dennis Handly
Acclaimed Contributor

Re: awk printing ' character

You don't. A single quote is used to quote the whole awk script. If you want to use a single quote, you need to use an awk program file then you don't need to quote:
ls | evil_quoting_script.awk
In the script:
#!/usr/bin/awk -f
{print "'" $1 "'"}

Or you can do it the direct (right) way with escapes:
ls | awk '{print "\x27" $1 "\x27"}'

>karthik3152: do it this way

The OP has said several times that's not what he wants.
Gavin Clarke
Trusted Contributor

Re: awk printing ' character

I should also point out that I asked this question approximately eight years ago!

I suppose I'd better close the thread.
Gavin Clarke
Trusted Contributor

Re: awk printing ' character

There are some right answers in here to what I found to be a tricky awk problem at the time.