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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printf and single quotes 1

Status
Not open for further replies.

achusa

Programmer
Apr 20, 2000
1
US
Is there simple way to print the single quote character using printf() in awk?<br><br>I have used the following in the past, but is cumbersome when the printf() statement is long...<br><br>awk -v QUOTE=&quot;'&quot; '{<br>&nbsp;&nbsp;printf(&quot;%s%s%s&quot;,QUOTE,$1,QUOTE) }' infile<br><br>--achusa
 
This nawk/gawk program ( won't work with standard awk )<br>does the job by setting $1 equal to $1 inside single quotes.<br><br>Use this BEGIN for comma separated values:<br><br>BEGIN{FS=OFS=&quot;,&quot;}<br><br>If the input data does not use (CSV) then don't use BEGIN.<br><br>nawk 'BEGIN{FS=OFS=&quot;,&quot;}<br><br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;$1 = &quot;\047&quot;$1&quot;\047&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;print<br><br>}' infile<br><br>Hope this helps you!<br><br>flogrr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top