Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk print string quotes

Status
Not open for further replies.

Kenton

Technical User
May 7, 2002
30
AU
Hi again

how do I print string quotes (") using awk?

I have this:
awk '{print $1, $2, $3} < infile

1,2,3
2,3,5

but I need

1,2,&quot;3&quot;
2,3,&quot;5&quot;

(I wish I had a UNIX manual!!)
Thanks
Kenton
[flush2]
 
Try:
Code:
printf &quot;%s,%s,\&quot;%s\&quot;\n&quot;, $1,$2,$3
Cheers Neil
 
Ummm, what am I doing wrong?

awk '{printf &quot;%s,%s,\&quot;%s\&quot;\n&quot;, $1,$2,$3}' < infile

now gives

1,2,3,,&quot;&quot;
2,3,5,,&quot;&quot;

Kenton

B-(
 
You must specify the input field separator to be a comma, using the -F option to awk. awk splits on space by default.
So your example should be:
Code:
awk -F',' '{printf &quot;%s,%s,\&quot;%s\&quot;\n&quot;, $1,$2,$3}' < infile
Cheers, Neil

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top