From: Paul Shapiro Date: 2009-06-22T05:15:02+09:00 Subject: Re: if column header contain regexp, delete column James Gray wrote: > On Jun 21, 2009, at 10:54 AM, Paul Shapiro wrote: > >> I need to see if a csv column header matches a pattern (see columns >> 2/3 >> below...S31 and S32) then delete the entire column. I've tried using: >> /(S[0-9]+\s\b)/ >> but i don't think the regexp is the problem. My script is using bother >> the rio and fastercsv gems. The fastercsv documentation has been very >> difficult for me to figure out (I'm new to ruby). Thanks. > > Paul, we need to improve your question asking skills a bit. :) > > It's hard for us to help when we have to read through a lot of prose > and even more code to understand the issue you are facing. You'll get > a lot better responses, and quicker, if you try to simplify your > questions down for us. "Here are the five lines I'm trying to use to > delete a column of CSV. Can you tell me why it's failing?" for example. > > Basically though, the steps are almost identical to what I gave you in > this message: > > http://groups.google.com/group/comp.lang.ruby/msg/c9f4c7b71465b6af > > Just copy the data, leaving out the column you don't want. > > I hope that helps. > > James Edward Gray II Ok. I would like to use fastercsv with maybe delete_if(&block) or delete(index_or_header), where the index is selected by a regular expression match. I have been unable to figure out the proper syntax for these functions. For demoing the task, I've been working with this code: table = FasterCSV::table('/Users/pshapiro/Desktop/Excel/csv/Attention.csv', :headers => true, :return_headers => true) junk = table.by_col.to_s Hopefully, that was a little more clear? James, I see you are the fastercsv developer, and I want to thank you for the help you have given me thus far! -- Posted via http://www.ruby-forum.com/.