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

Adding " to each end of a field in an awk print statement 1

Status
Not open for further replies.

RaoulZa

Technical User
Sep 5, 2002
14
GB
Can anybody tell me the correct character to use so that i can change data from non quotes to quotes please?

For example

12345,abcde,12346 to "12345","abcde","12346"

i thought it would be \" but its telling me its not correctly parsed


thanks very much
 
Use "\042" e.g.

BEGIN {FS=","}
{
print "\042" $1 "\042" "," "\042" $2 "\042" "," "\042" $3 "\042"
} CaKiwi
 
Hi:

This works on my Solaris 7 box:


echo "111,abc,222"|awk ' BEGIN { FS="," ; OFS=","}
{
for (i=1; i<=NF; i++)
$i=&quot;\&quot;&quot;$i&quot;\&quot;&quot;

print $0
}
 
Thanks very much both of you.

Before i got the answers along I decided to do it the long winded way, and output tilders around the fields, converting them to quotes using sed &quot;s /\~/\&quot;/g&quot;.

But my thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top