Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

QIF To CSV Conversion Script In Ruby

DZone's Guide to

QIF To CSV Conversion Script In Ruby

·
Free Resource
// 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
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}