1753905 Members
9988 Online
108810 Solutions
New Discussion юеВ

Little help awk

 

Little help awk

Hello everybody, how you doing?

Can anyone help me in a case? I have a list with two names:

atibaia:/ # cat list
atibaia
aurora

I need to print this names between apostrophe, something like this:
'atibaia'
'aurora'

But, I need do this, using awk. I've tried some comands cat list | awk '{ print "'" $1 "'" } or cat list | awk '{ print "\'"$1"\'" }' and nothing... hahaha

Any idea to help me ?!?!?!

Thank you very much

Andr├й
Andre Augusto
3 REPLIES 3
Jonathan Fife
Honored Contributor

Re: Little help awk

You could set the single quote as a variable using the -v option:

$ cat list | awk -vqt="'" '{print qt$1qt}'
'atibaia'
'aurora'
Decay is inherent in all compounded things. Strive on with diligence

Re: Little help awk

Great Jonathan...

Thank you very much for your help...

Regards

Andr├й
Andre Augusto
Dennis Handly
Acclaimed Contributor

Re: Little help awk

I too couldn't figure out how many "\" are needed to quote the "'". But you could create an awk script with the "'" already there:
#!/usr/bin/ksh

cat < xx_list
atibaia
aurora
EOF

cat <<\EOF > awk_file
{ print "'" $1 "'" }
EOF

awk -f awk_file xx_list

rm -f xx_list awk_file