How to manage Tab & Comma separated filds form single text f

Hi,

I am modifying on script. I am using this script to import data form
text-delimited file into PosgresSql database.

I have already setup a code for tab separation but facing problem in
comma separation. In text-delimited file there is foulr field which are
inter related.
first “organization & City” and Second “State & Country”. Where
organization & City are separated with commas ", " and State & Country.
But when the script will execute it will split the not only tab
separated fields but also as and when he found comma separated field
i.e.organization & City then it will split the Organization & city and
stored it the respected field.

Could anybody please help me in this> I have no such exposure to Ruby. I
have here attached the data_importer.rb file for your reference also
need help here pasted code.

============================================================
f.read.each do |l|
if counter > 0
tokens = l.split(/\t/).collect{|ss| ss.delete(""") }
hn = tokens[0]
pgn = tokens[1]
sn = tokens[2]
pio = tokens[3]
dio = tokens[4]
org = tokens[5]
al1 = tokens[6]
al2 = tokens[7]
ci = tokens[8]
st = tokens[9]
pc = tokens[10]
co = tokens[11]
te = tokens[12]
fax = tokens[13]
ew = tokens[14]
eo = tokens[15]
wa = tokens[16]
at1 = tokens[17]
at2 = tokens[18]
at3 = tokens[19]
c1 = tokens[20]
c2 = tokens[21]
c3 = tokens[22]

      begin

======================================

Regards,

Bhupendra

Please find more below more hints on what the code is :

============================================
begin
f.read.each do |l|
if counter > 0
tokens = l.split(/\t/).collect{|ss| ss.delete(""") }
#tokens1 = l.split(/, /)
#tokens2 = l.split(/, /)
#tokens[5] = l.split(/, /)
hn = tokens[0]
pgn = tokens[1]
sn = tokens[2]
pio = tokens[3]
dio = tokens[4]
#tokens[5] = l.split(/, /)
org = tokens[5]
org1 = l.find(’, ')
ci = l[:org1]
al1 = tokens[6]
al2 = tokens[7]
ci = tokens[8]
st = tokens[9]
pc = tokens[10]
co = tokens[11]
te = tokens[12]
fax = tokens[13]
ew = tokens[14]
eo = tokens[15]
wa = tokens[16]
at1 = tokens[17]
at2 = tokens[18]
at3 = tokens[19]
c1 = tokens[20]
c2 = tokens[21]
c3 = tokens[22]

      begin
        cn = Contact.find(:first, :conditions => 

[“preferred_given_names = ? and surname = ? and (email_work = ? OR
email_work IS NULL)”, pgn, sn, ew])
found = true
#found = false
if ! cn
found = false
cn = Contact.new
cn.honorific = hn
cn.preferred_given_names = pgn
cn.surname = sn
cn.position_in_organisation = pio
cn.division_in_organisation = dio
cn.organisation = org
cn.address_line_1 = al1
cn.address_line_2 = al2
cn.city = ci
cn.state = st
cn.postal_code_zip = pc
cn.country = co
cn.phone = te
cn.fax = fax
cn.email_work = ew
cn.email_other = eo
cn.web_address = wa
cn.affiliation_type = at1
cn.affiliation_type2 = at2
cn.affiliation_type3 = at3
cn.created = Time.now
cn.modified = Time.now
cn.save
end

Bhupendra Chaudhari wrote:

Hi,

I am modifying on script. I am using this script to import data form
text-delimited file into PosgresSql database.

I have already setup a code for tab separation but facing problem in
comma separation. In text-delimited file there is foulr field which are
inter related.
first “organization & City” and Second “State & Country”. Where
organization & City are separated with commas ", " and State & Country.
But when the script will execute it will split the not only tab
separated fields but also as and when he found comma separated field
i.e.organization & City then it will split the Organization & city and
stored it the respected field.

Could anybody please help me in this> I have no such exposure to Ruby. I
have here attached the data_importer.rb file for your reference also
need help here pasted code.

============================================================
f.read.each do |l|
if counter > 0
tokens = l.split(/\t/).collect{|ss| ss.delete(""") }
hn = tokens[0]
pgn = tokens[1]
sn = tokens[2]
pio = tokens[3]
dio = tokens[4]
org = tokens[5]
al1 = tokens[6]
al2 = tokens[7]
ci = tokens[8]
st = tokens[9]
pc = tokens[10]
co = tokens[11]
te = tokens[12]
fax = tokens[13]
ew = tokens[14]
eo = tokens[15]
wa = tokens[16]
at1 = tokens[17]
at2 = tokens[18]
at3 = tokens[19]
c1 = tokens[20]
c2 = tokens[21]
c3 = tokens[22]

      begin

======================================

Regards,

Bhupendra

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs