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

   1  
   2  #!/usr/bin/env ruby
   3  
   4  require 'rubygems'
   5  require 'fileutils'
   6  
   7  if ARGV.size < 1
   8          puts "Usage: #{$0} file.qif"
   9          exit
  10  end
  11  
  12  input = File.new(ARGV[0])
  13  output = [File.basename(ARGV[0]).split('.')[0..-2], 'csv'].join('.')
  14  output = File.new(output, 'w+')
  15  output.write("date,amount,description,transaction id, address\n")
  16  
  17  entries = input.read.split("^\n")
  18  entries.compact
  19  for entry in entries
  20          e = entry.match(/D(.*)\nT-?(.*)\nP(.*)\nN(.*)\nA(.*)\n/).to_a[1..-1]
  21          e[1] = e[1].to_f rescue nil
  22          e[-1] = "\"#{e[-1]}\""
  23          output.write("#{e.join(',')}\n")
  24  end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS