From: rio4ruby Date: 2007-08-17T10:50:03+09:00 Subject: Re: grep a csv? On Aug 16, 1:43 pm, Michael Linfield wrote: > Pe�a, Botp wrote: > > From: rio4ruby [mailto:Christopher.Kleck...@gmail.com] > > # require 'rio' > > # rio('filename.csv').chomp.lines(/Blah[^,]*/) do |line,m| > > # rio(m) + '.csv' << line + $/ > > # end > > > simply amazing. btw, how does rio handle big files, does it load them > > whole in memory? > > > thanks for rio. > > kind regards -botp > > it seems things have been amped a few levels of complication since my > first few post lol. The quote above might seem like the cleanest way to > do this, however if i use this method...ill still need the commas, > because when u take a csv and put it in simple text, the commas are what > seperate the columns. so maybe it should look something like this? > > require 'rio' > > rio('filename.csv').chomp.lines(/Blah1/) do |line,m| > rio(m) + '.csv' << line + $/ > end > ### > > -- > Posted viahttp://www.ruby-forum.com/. You are right, that was a poorly thought out regular expression. One could also use Rio's csv mode (which uses the stdlib csv): rio('filename.csv').chomp.csv.records(/Blah\w*/) do |rec,m| rio(m.to_s + '.csv').csv << rec end But this also is definately NOT a robust solution.