From: Alex Gutteridge Date: 2007-08-16T13:58:00+09:00 Subject: Re: grep a csv? On 16 Aug 2007, at 13:29, Michael Linfield wrote: > Alex Gutteridge wrote: >> On 16 Aug 2007, at 13:08, Michael Linfield wrote: >> >> Though why don't you just use: >> >> res = File.readlines('filename.csv').grep(/Blah1/) >> >> Alex Gutteridge > > can i push that into a file to temporarily use to pull all the Blah1 > data from, then at the end of the program delete Blah1.csv ? Sure, use tempfile, but I think botp has shown why you don't really need the temporary file (unless there's part of this problem I'm not understanding): irb(main):001:0> puts File.readlines('filename.csv') this, is , a , test, foo this, is , a , test, bar this, is , a , test, Blah1 this, is , a , test, bar this, Blah, is , a , test this, is , a , Blah, test => nil irb(main):002:0> puts File.readlines('filename.csv').grep(/Blah1/) this, is , a , test, Blah1 => nil irb(main):003:0> require 'tempfile' => true irb(main):004:0> tf = Tempfile.new('csv') => # irb(main):005:0> tf.puts File.readlines('filename.csv').grep(/Blah1/) => nil irb(main):006:0> tf.close => nil irb(main):007:0> tf.open => # irb(main):008:0> puts tf.gets this, is , a , test, Blah1 => nil Alex Gutteridge Bioinformatics Center Kyoto University