title: Ruby: Using a csv as a database
body: <p>I think I may not have done a good enough job explaining my question the first time.</p>
  
  <p>I want to open a bunch of text, and binary files and scan those files with my regular expression. What I need from the csv is to take the data in the second column, which are the paths to all the files, as the means to point to which file to open.</p>
  
  <p>Once the file is opened and the regexp is scanned thru the file, if it matches anything, it displays to the screen. I am sorry for the confusion and thank you so much for everything! –</p>
  
  <p>Hello,</p>
  
  <p>I am sorry for asking what is probably a simple question. I am new to ruby and will appreciate any guidance.</p>
  
  <p>I am trying to use a csv file as an index to leverage other actions.</p>
  
  <p>In particular, I have a csv file that looks like:</p>
  
  <pre><code> id, file, description, date
   1, /dir_a/file1, this is the first file, 02/10/11
   2, /dir_b/file2, this is the second file, 02/11/11
  </code></pre>
  
  <p>I want to open every file defined in the "file" column and search for a regular expression.</p>
  
  <p>I know that you can define the headers in each column with the CSV class</p>
  
  <pre><code>require 'rubygems'
  require 'csv'
  require 'pp'
  
  index = CSV.read("files.csv", :headers =&gt; true)
  
  index.each do |row|
    puts row ['file']
  end
  </code></pre>
  
  <p>I know how to create a loop that opens every file and search's for a regexp in each file, and if there is one, displays it:</p>
  
  <pre><code>regex = /[0-9A-Za-z]{8,8}-[0-9A-Za-z]{4,4}-[0-9A-Za-z]{4,4}-[0-9A-Za-z]{4,4}-[0-9A-Za-z]{12,12}/
  
  Dir.glob('/home/Bob/**/*').each do |file|
    next unless File.file?(file)
    File.open(file, "rb") do |f|
      f.each_line do |line|
        f.each_line do |line|
          unless (pattern = line.scan(regex)).empty?
            puts "#{pattern}"
          end
        end
      end
    end
  end
  </code></pre>
  
  <p>Is there a way I can use the contents of the second column in my csv file as my variable to open each of the files, search the regexp and if there is a match in the file, output the the row in the csv that had the match to a new csv?</p>
  
  <p>Thank you in advance!!!! </p>