views:

43

answers:

1

I have some address data which has been exported from a database. If the address had multiple lines, the exported data has joined all the lines into one string with the former lines being separated by dollars signs. Here's one of the addresses:

INFORMATION DELIVERY DEPT$704 CHERRY ST$ATLANTA, GA 30332-0900

I'm splitting this into an array on the dollar sign and outputting the three array elements into separate tab-separated fields with printf. For some reason, it comes out like this:

INFORMATION DELIVERY DEPT 704 CHERRY ST "ATLANTA, GA 30332-0900"

I don't want the quotes around that final field. Can anyone explain why this is happening and how to suppress it?

This is being done in Windows Vista with gawk3.1.6.

Thanks! gary

As requested, here's the code. I'm using the length function so that my printf can be passed the length for each record I read.

if ($6 ~ /\$/) split($6, arr, "$") address = arr[1] addresstwo = arr[2] addressthree = arr[3] addressLength = length(address) addressTwoLength = length(addresstwo) addressThreeLength = length(addressthree)

else {
    address = $6
    addressLength = length($6)
    addresstwo = ""
    addressTwoLength = length(addresstwo)
addressthree = ""
    addressThreeLength = length(addressthree)
    }

printf("%*s\t%*s\t\%*s\n",
      addressLength, address, addressTwoLength, addresstwo, addressThreeLength, addressthree)

Edit on May 19: I guess this will just remain a mystery. Today, running the same code and the same input files, it's NOT putting in the double quotes.

A: 

I'm not entirely familiar with Gawk and am surprised if it's at fault, but this looks like some function is trying to be "helpful" and format the strings for use in a CSV, which would require the quotes in a field that includes a comma.

Chuck
Thanks. I noticed that it was happening in the only part of the string that has a comma. I guess I should look into the behavior of split and printf.
Gary