On Tuesday 06 January 2009, Orion Vianna wrote:
> Chris Knadle wrote:
> > For situations where there are names/addresses/etc in a vertical 
list
> > seperated by one or more blank lines, that's one situation where 
I'd
> > probably use a Bash script or a Python program to turn the data 
into
> > CSV format rather than try to import with Excel.
> >
> >
> >    -- Chris
>
> Do you mean a custom script?

Yes.  Especially in this situation, where some entries have more
information than others, if you want to import this cleanly you'll
probably have to build something custom to be able to recognize
what the information *IS* in order to figure out which CSV field
it needs to go into, and thus figuring out what information an
entry *DOESN'T* have.  For instance, you can find the maximum
number of elements an entry can have (which will also be the
number of CSV elements each entry will have at the end), and then
by a count you can tell how many an entry is missing. 

Generally speaking the way I usually approach this type of problem
is to use an array to pull in all of the elements of a single entry
until there's an empty line, and then parse the array.  Arrays in
Bash are a bit limited but it would be enough to handle this
problem, if you decide to try making a Bash script for this.  The
only problem with Bash is that it's generally not powerful enough
in and of itself to do a complicated job, so you end up branching
out into Sed, Awk, Cut, and other things that have yet another
syntax to have to deal with.

There's also a chance you could do some web searching and find a
script that someone put together for this already, because it is
likely to be a common enough problem that somemone may have made
a somewhat general purpose utility to do it.  It's not a bad idea
to search for a solution to a problem first, just to make sure
you're not about to re-design the wheel, so-to-speak.

> This could be an interesting exercise since I have been learning
> python but I don't think I can do it quick enough. 

If you're already learining Python then you might be able to
solve this with a couple of days of effort.  If nothing else it'll
be a good excuse to learn more about Python lists and string
manipulation, which will definitely come in handy with similar
types of problems you'll likely run into again.

> Thank you for your ideas :o)

Suggestions are usually easier to give than programming the real 
solution is.  ;-)

Cheers.

   -- Chris

-- 

Chris Knadle
[email protected]
_______________________________________________
Mid-Hudson Valley Linux Users Group                  http://mhvlug.org
http://mhvlug.org/cgi-bin/mailman/listinfo/mhvlug
Upcoming Meetings (6pm - 8pm)                         MHVLS Auditorium
  Jan 7 - Ruby on Rails
  Feb 4 - TBD

Reply via email to