Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Shawn Pyle

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

QIF to CSV conversion script in Ruby

// Converts QIF files to CSV files

#!/usr/bin/env ruby

require 'rubygems'
require 'fileutils'

if ARGV.size < 1
        puts "Usage: #{$0} file.qif"
        exit
end

input = File.new(ARGV[0])
output = [File.basename(ARGV[0]).split('.')[0..-2], 'csv'].join('.')
output = File.new(output, 'w+')
output.write("date,amount,description,transaction id, address\n")

entries = input.read.split("^\n")
entries.compact
for entry in entries
        e = entry.match(/D(.*)\nT-?(.*)\nP(.*)\nN(.*)\nA(.*)\n/).to_a[1..-1]
        e[1] = e[1].to_f rescue nil
        e[-1] = "\"#{e[-1]}\""
        output.write("#{e.join(',')}\n")
end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS