Scripting question, new problem
Patton Echols
p.echols at comcast.net
Sat Dec 11 21:22:45 UTC 2010
On 12/11/2010 04:14 AM, ms wrote:
> On 11/12/10 02:44, Patton Echols wrote:
>
>> I'm still working on my script to import data into gmail from a
>> proprietary database. Most is working ok. The work flow is to export
>> from the database to a csv flat file, then run the script to extract the
>> data and reformat to a new CSV that gmail can swallow. (An absurd
>> amount of googling spent on that!)
>>
>> Current problem is the export a subset of the database records have, for
>> "street address" a two line entry like this:
>>
>> 123 main street
>> Apartment A
>>
>> When that is exported, it adds a carriage return to the CSV file.
>>
>> What I'd like to do is have the script walk through the file, and if
>> there is a line without 13 fields, combine it with the next line.
>>
>> Since all the date is strings, and quoted, the alternative would be to
>> find a line that does not start with a literal " and "backspace" once.
>>
>> Can anyone suggest where to start?
>>
>> (By the way, yes I could manually fix the file. But the intention is to
>> make this a process that can be repeated weekly, sort of like a one way
>> sync.)
>>
>
> In Python is trivial -and surely it is also in Perl or Ruby. In what
> language are you doing the script?
> Perhaps better to ask to the language mailing list.
>
> cheers,
> m.
>
>
Thanks, what I am working on is a shell script. So far it's pretty
simple and looks like this:
[code]
#! /bin/bash
# Add google required field names to the new CSV:
echo "\"First Name\",\"Middle Name\",\"Last Name\",\"E-mail
Address\",\"E-mail 2 Address\",\"Business Street\",\"Business
City\",\"Business State\",\"Business Postal Code\",\"Home
Phone\",\"Business Phone\",\"Mobile Phone\"" > export.csv
# Look for email addresses in fields 4 & 5, check for duplicate names,
and print each line to the new file
gawk -F, '{ if (match($4$5, "@") && !seen[$1 " " $3]) { seen[$1 " " $3]
= 1 ; print
$1","$2","$3","$4","$5","$7","$8","$9","$10","$13","$12","$11 }}'
gmail-export.txt >> export.csv
[/code]
More information about the ubuntu-users
mailing list