require 'dbi' insert_sql = "some SQL statement" DBI.connect( 'dbi:Mysql:database=some_db;host=some_host', 'user', 'password' ) { |dbh| dbh.prepare( insert_sql ) { |sth| File.open( File.join( File.dirname(__FILE__), 'some_file.txt' ) ) { |file| # Strip off the first two lines (1..2).each { file.gets } file.each { |line| fields = line.strip.split( ',' ) fields.each { |field| field.gsub!(/"/, '') field.strip! } # Adjust for stoopidity fields[5] = (2 - fields[5].to_i) + 1 ary = [ fields.values_at(1..4, 4..5), 0, 0 ].flatten sth.execute( *ary ) } } } }