On Jun 21, 2009, at 3:15 PM, Paul Shapiro wrote: > 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. Awesome. That helped. Thanks. I would probably try something like this: $ cat data.csv A,B,C,D 1,2,3,4 5,6,7,8 $ cat del_col.rb #!/usr/bin/env ruby -wKU require "rubygems" require "faster_csv" table = FCSV.table("data.csv") table.headers.each do |h| next unless h.to_s =~ /\A[bd]\z/i table.delete(h) end puts table __END__ $ ruby del_col.rb a,c 1,3 5,7 Hope that helps. James Edward Gray II