I currently have a large text file based address book(for myself, not spamming) that I am working on making suitable for import into a database. To do this I need comma separated values. How would I go about adding a comma after the state in the person's mailing address?
An example record:
Name: Bob Fakeyhead
Title: Old Boss
Phone: 555-555-5555
Mailing: 23456 Something Street
OldPlace, WA 55555
I need a ',' after WA.
Right now I am reading the file into a string to edit it and then writing the comma separated version back out to file. For most of the other fields I can just add a comma to the end of each line and get the desired effect but for the Address I need to have multiple fields and therefore multiple commas per line.
Thank you,
Matthew Margolis
Matthew Margolis <mrmargolis@wisc.edu> writes:
I currently have a large text file based address book(for myself, not
spamming) that I am working on making suitable for import into a
database. To do this I need comma separated values. How would I go
about adding a comma after the state in the person's mailing address?
An example record:
Name: Bob Fakeyhead
Title: Old Boss
Phone: 555-555-5555
Mailing: 23456 Something Street
OldPlace, WA 55555
If you are using Ruby 1.8, you can use the CSV module.
http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/
::::::::::::::
z.rb
::::::::::::::
···
#
# z.rb
#
# Copyright (c) 2004 by Daniel Kelley
#
#
require 'csv'
writer = CSV.generate('csvfile.csv')
writer << ['Name', 'Title', 'Phone', 'Mailing']
writer << ['Bob Fakeyhead', 'Old Boss', '555-555-5555', '23456 Something Street
OldPlace, WA 55555']
writer.close
::::::::::::::
csvfile.csv
::::::::::::::
Name,Title,Phone,Mailing
Bob Fakeyhead,Old Boss,555-555-5555,"23456 Something Street OldPlace, WA 55555"
--
Daniel Kelley - San Jose, CA
For email, replace the first dot in the domain with an at.
Daniel Kelley wrote:
Matthew Margolis <mrmargolis@wisc.edu> writes:
I currently have a large text file based address book(for myself, not spamming) that I am working on making suitable for import into a database. To do this I need comma separated values. How would I go about adding a comma after the state in the person's mailing address?
An example record:
Name: Bob Fakeyhead
Title: Old Boss
Phone: 555-555-5555
Mailing: 23456 Something Street
OldPlace, WA 55555
If you are using Ruby 1.8, you can use the CSV module.
http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/
::::::::::::::
z.rb
::::::::::::::
#
# z.rb
# # Copyright (c) 2004 by Daniel Kelley
# #
require 'csv'
writer = CSV.generate('csvfile.csv')
writer << ['Name', 'Title', 'Phone', 'Mailing']
writer << ['Bob Fakeyhead', 'Old Boss', '555-555-5555', '23456 Something Street OldPlace, WA 55555']
writer.close
::::::::::::::
csvfile.csv
::::::::::::::
Name,Title,Phone,Mailing
Bob Fakeyhead,Old Boss,555-555-5555,"23456 Something Street OldPlace, WA 55555"
Thanks for the reply but I already have decided on what database I will be using so I don't need CSV, I just need to find a way to insert a comma after the state in the person's address.
-Matthew Margolis
Matthew Margolis <mrmargolis@wisc.edu> writes:
I currently have a large text file based address book(for myself, not
spamming) that I am working on making suitable for import into a
database. To do this I need comma separated values. How would I go
about adding a comma after the state in the person's mailing address?
An example record:
Name: Bob Fakeyhead
Title: Old Boss
Phone: 555-555-5555
Mailing: 23456 Something Street
OldPlace, WA 55555
If you are using Ruby 1.8, you can use the CSV module.
http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/
[...]
require 'csv'
If I understand him correctly, this solves creating correct csv output,
but he has to parse the input.
A regexp to split the adress line would be
OldPlace, WA 55555
raise "Unknown address format" unless /(.*?),\s*(\w*)\s*(\d*)/ =~ address_line
address[:town] = $1; address[state] = $2, address[:code] => $3}
regards,
Brian
···
On Sat, 25 Sep 2004 10:36:13 -0700, Daniel Kelley wrote:
--
Brian Schröder
http://www.brian-schroeder.de/